Query to get the last change in the particular column

Hello

[Update]
I need help to find the last change to a particular to a table column.

tell the table as
t_address (phone_number, first_name, user_id, change_date)

I need to find what was her last phone number change happened.
Well, the date of change is updated for any changes in this table. I want to understand the change_date only when a particular field has changed (from the previous value). It seems a little complicated for me.

t_address (phone_number, first_name, user_id, change_date)

say for any change of phone_number, name it will be an entry in this table t_address. and change_date will be the inserted date.

say

USR_ID phone_number name change_date
Hari 123 Henderson 12/12/2011
Hari hari 123 12/11/2011
Hari hari 345 12/10/2011

now my requirement is to get 12/11/2011 as on that particular date, the phone number has changed from previous value.


Please suggest.

Published by: user7807429 on Sep 10, 2012 11:51

Hello

WITH t_address AS (
SELECT 'hari' usr_id, 123 phone_number, 'harinath' first_name ,DATE '2011-12-12' change_date FROM dual UNION ALL
SELECT 'hari' usr_id, 123 phone_number, 'hari' first_name ,DATE '2011-12-11' change_date FROM dual UNION ALL
SELECT 'hari' usr_id, 345 phone_number, 'hari' first_name ,DATE '2011-12-10' change_date FROM dual
)
SELECT  usr_id
       ,phone_number
       ,prev_phone_number
       ,first_name
       ,change_date
FROM    (
    -- Select only the rows where the phone number changed
    -- and max phone change date for each user
    SELECT  usr_id
           ,phone_number
           ,first_name
           ,change_date
           ,prev_phone_number
           ,MAX(change_date)
            OVER (PARTITION BY usr_id
                  ORDER BY change_date
                  RANGE BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING
                  ) max_change_date
    FROM    (
        -- Select the data together with the phone number of the previous row
        SELECT  usr_id
               ,phone_number
               ,first_name
               ,change_date
               ,LAG(phone_number)
                OVER (PARTITION BY usr_id
                      ORDER BY change_date
                      ) prev_phone_number
        FROM    t_address
        )
    -- check for difference with decode because phone_number might be NULL
    WHERE   DECODE( prev_phone_number, phone_number, 1, 0 ) = 0
    )
WHERE   change_date = max_change_date;

USR_ID PHONE_NUMBER PREV_PHONE_NUMBER FIRST_NAME CHANGE_DATE
------ ------------ ----------------- ---------- -----------
hari            123               345 hari       11.12.2011 

You can include the current value if you join more intimate in the select t_user.

Concerning
Marcus

Tags: Database

Similar Questions

  • SQL query to get the NULL records after the last matching flag

    I have a xx1 table with id and flag columns. So I want the data in this table, after the last flag matched. I want that data to id 7 in the rooms. Even if the id 2,3,5 are null flag 'Y' was at 6. ID so I need a query to get the data of the xx1 table after the last correspondence flag (from 7 to 9 id).

    SQL > create table xx1

    2 (identification number,

    3 flag varchar2 (10));

    Table created.

    SQL > insert into xx1 values (1, 'Y');

    1 line of creation.

    SQL > insert into values xx1 (2, null);

    1 line of creation.

    SQL > insert into values xx1 (3, null);

    1 line of creation.

    SQL > insert into xx1 values (4, 'Y');

    1 line of creation.

    SQL > insert into values xx1 (5, null);

    1 line of creation.

    SQL > insert into xx1 values (6, 'Y');

    1 line of creation.

    SQL > insert into values xx1 (7, null);

    1 line of creation.

    SQL > insert into values xx1 (8, null);

    1 line of creation.

    SQL > insert into values xx1 (9, null);

    1 line of creation.

    SQL > select * from xx1.

    FLAG OF THE ID

    ---------- ----------

    1. IS

    2

    3

    4. IS

    5

    6. IS

    7

    8

    9

    9 selected lines.

    SQL >

    Hello

    user11164339 wrote:

    Hi Frank - when I run the query, I don't see the results data.

    I get

    FLAG OF THE ID

    ----- ----------

    7

    8

    9

    What you do differently?

  • IOM sql Query to get the status of the failed task

    Hello world

    We have an obligation as we need to get the status of a particular task (say Create User in OID - Completed\Rejected status resource) for the particular user. We are able to get the status of the provisioed of resources to the user but not the status of the special mission which is trigerred for the user.can someone put some light on it. We must have the SQL query to do this.

    Thanks in advance.

    Kind regards
    MKN

    Hello
    Use this query to get the status of the task, also check the cooments

    SELECT USR. USR_LOGIN, OSI. SCH_KEY, ANN. SCH_STATUS, STA. STA_BUCKET OF
    OSI, CHS, STA, MIL, TOS, PKG, OUEDRAOGO, USR, OBJ, OST
    WHERE OSI.MIL_KEY = MIL.MIL_KEY
    AND ANN. SCH_KEY = OSI. SCH_KEY
    AND STA. STA_STATUS = SCH. SCH_STATUS
    AND TOS. PKG_KEY = PKG. PKG_KEY
    AND MIL. TOS_KEY = TOS. TOS_KEY
    AND OUÉDRAOGO. USR_KEY = USR. USR_KEY
    AND OUÉDRAOGO. OST_KEY = OST. OST_KEY
    AND OST. OBJ_KEY = OBJ. OBJ_KEY
    AND OSI. ORC_KEY = OUEDRAOGO. ORC_KEY
    AND OBJ. OBJ_NAME = "User AD".
    AND OST. OST_STATUS = "Provisioning" - filter accordinglly
    AND STA. STA_BUCKET = 'pending' - filter accordinglly
    AND PKG. PKG_NAME = "AD User" - filter accordinglly
    AND MIL.MIL_NAME = 'System' - filter accordinglly Validation
    ;
    Thank you
    Kuldeep

  • Query to get the data of the column and the metadata in the same set of results.

    Is it possible to build a query to get the values of the columns in a table and also be able to get some metadata (data type, data_length, data_precision, data_scale) for columns in the same set of results.

    If I use a join, have a common value to join on the two tables?

    you use a cross join, not requiring common values.

    create table T (n number, d date, v varchar2(30));
    insert into T values (1,sysdate,'ABC');
    commit;
    
    select C.column_name, c.data_type, c.data_length,
    case c.column_id
     when 1 then to_char(T.N)
     when 2 then to_char(T.D)
     when 3 then T.V
    end VALUE
    from USER_TAB_COLUMNS C, T
    where C.table_name='T'
    order by c.column_id;
    
  • How to write a simple select query to get the data of the table as an XML.

    How to write a simple select query to get the data of the table as an XML. In the query, I'm just adding items below which i need be there in the XML document
    select '<test_tag>'||EMP_NAME||'</test_tag>','<date>'||sysdate||'</date>' 
    from temp_table where id_num BETWEEN 1 AND 10;
    I have need to add the root tag as well in the beginning and the end of < root > < / root > this xml file. Please advice if this is possible with the select query
    without using XMLGEN, XMLQUERY or any other packages built and function?

    I need to URL escapes with the UTF-8 code points that we have already achieved using the utl_http package. Please help how to do that without using the utl_http package.

    What is wrong with him?

    At present, the only way I can think of to avoid a call to UTL_HTTP. SET_BODY_CHARSET is to write your own little wrapper.
    In this way, you can specify the Boolean parameter or omit it if you choose to use named parameters:

    SQL> create or replace function my_url_escape (url in varchar2)
      2  return varchar2
      3  deterministic
      4  is
      5  begin
      6   return utl_url.escape(url, false, 'AL32UTF8');
      7  end;
      8  /
    
    Function created
    
    SQL> select my_url_escape('http://some.uri.com/param?lang=fr&text=contrôle') from dual;
    
    MY_URL_ESCAPE('HTTP://SOME.URI
    --------------------------------------------------------------------------------
    http://some.uri.com/param?lang=fr&text=contr%C3%B4le
     
    
  • I have run this query to get the result as below, but, even if my query is running fine, that I do not get the expected result.

    I'm looking for only column compare to my same target table as a table source.

    My query:


    Select case when column_name_s is null and column_name_t is not null

    then "alter table GRADE_CONVERSION drop | column_name_t | ';'

    When column_name_s is not null and column_name_t is null

    then "alter table GRADE_CONVERSION add | column_name_s | ' ' || data_type_s | « ; »

    else 'alter table modify GRADE_CONVERSION | column_name_t | ' ' || data_type_t | « ; »

    alterations of the end

    from (select s.column_name column_name_s, t.column_name column_name_t,

    s.data_type data_type_s, t.data_type data_type_t

    (select column_name, column_id, data_type

    of all_tab_cols@database

    where owner = 'erhan.

    and table_name = "GRADE_CONVERSION."

    + 1

    full outer join

    (select column_name, column_id, data_type

    of all_tab_cols@database

    where owner = 'sarigul.

    and table_name = "GRADE_CONVERSION."

    + 6

    on s.column_name = t.column_name

    )




    Tables:



    Target table: table GRADE_CONVERSION in sarigul@database


    LETTER_GRADEVARCHAR2 (2)
    GRADE_POINTNUMBER (3.2)
    MAX_GRADENUMBER (3)
    MIN_GRADENUMBER (3)




    Table source: Table GRADE_CONVERSION in erhan@database

    LETTER_GRADEVARCHAR2 (2)
    GRADE_POINTNUMBER (3.2)
    MAX_GRADENUMBER (3)
    MIN_GRADENUMBER (3)
    CREATED_BYVARCHAR2 (30)
    CREATED_DATEDATE
    MODIFIED_BYVARCHAR2 (30)
    MODIFIED_DATEDATE



    want to see output that is similar to this * (please ignore the names of column here it's just a clear example :))


    ALTER table Target_table change BOOK_ID Varchar2 (4);

    ALTER table Target_table I addSBN_10 Varchar2(13), null;

    ALTER table drop TITLE Target_table;

    Erhan_toronto wrote:

    1.I used src.nullable src_nullable and tgt.nullable tgt_nullable but only show Yes as below: but want to see the result as not null or null

    ALTER table TEST_TARGET change the NUMBER of MAX_GRADE (3, 2) Yes

    Ok. So it's all about the Yes and the no decoding to Default Null or Not Null, isn't it?

    So, to test, change one of the table of sample for NOT NULL columns in the source table, and then run the following query:

    with src as
    (
      select src.table_name src_table_name, src.column_name src_col_name, src.data_type src_data_type, src.data_length src_data_len, src.data_precision src_data_precision, src.data_scale src_data_scale,
             src.nullable src_nullable
        from user_tab_columns src
       where table_name = 'TEST_SOURCE'
    ),
    tgt as
    (
      select tgt.table_name tgt_table_name, tgt.column_name tgt_col_name, tgt.data_type tgt_data_type, tgt.data_length tgt_data_len, tgt.data_precision tgt_data_precision, tgt.data_scale tgt_data_scale,
             tgt.nullable tgt_nullable
        from user_tab_columns tgt
       where table_name = 'TEST_TARGET'
    ),
    col_details as
    (
      select src.src_table_name, nvl(tgt.tgt_table_name, first_value(tgt_table_name) over(order by tgt_table_name nulls last)) tgt_table_name,
             src.src_col_name, src.src_data_type, src.src_data_len, src.src_data_precision, src.src_data_scale, src.src_nullable,
             tgt.tgt_col_name, tgt.tgt_data_type, tgt.tgt_data_len, tgt.tgt_data_precision, tgt.tgt_data_scale, tgt.tgt_nullable
        from src
        left outer join tgt
          on (
              src.src_col_name = tgt.tgt_col_name
             )
    )
    select *
      from (
            select case
                    when tgt_data_type != src_data_type or tgt_data_len != src_data_len or tgt_data_precision != src_data_precision or tgt_data_scale != src_data_scale or src_nullable != tgt_nullable
                      then 'alter table ' || tgt_table_name || ' modify ' || tgt_col_name || ' ' || src_data_type || ' (' ||
                      case when src_data_type in ('DATE') then null
                           else
                                case
                                  when src_data_type in ('VARCHAR', 'VARCHAR2')
                                    then nvl(to_char(src_data_len), ' ') || ') '
                                  else  decode(nvl(src_data_precision, -1), -1, null, nvl(to_char(src_data_precision), ' ') || ', ' || nvl(to_char(src_data_scale), ' ') || ')')
                                end
                      end
                      || decode(src_nullable, 'NO', ' NOT NULL', ' DEFAULT NULL')
                    when tgt_col_name is null
                      then 'alter table ' || tgt_table_name || ' add ' || src_col_name || ' ' || src_data_type ||
                      case when src_data_type in ('DATE') then null
                           else
                                case
                                  when src_data_type in ('VARCHAR', 'VARCHAR2')
                                    then nvl(to_char(src_data_len), ' ') || ') '
                                  else  decode(nvl(src_data_precision, -1), -1, null, nvl(to_char(src_data_precision), ' ') || ', ' || nvl(to_char(src_data_scale), ' ') || ')')
                                end
                      end
                      || decode(src_nullable, 'NO', ' NOT NULL', ' DEFAULT NULL')
                   end alter_statement
              from col_details
            )
    where alter_statement is not null;
    

    Erhan_toronto wrote:

    2. when I run below under user sarigul and erhan I get the result as OWNER, TABLE_NAME, COLUMN_NAME DATA_TYPE... I have a link between two users. They have access to two tables.

    • Select * from all_tab_columns

    where owner = 'erhan' and table_name = "TEST_SOURCE."

    • Select * from all_tab_columns

    where owner = 'sarigul' and table_name = "TEST_TARGET."

    Alright. This means that you both users are on the same database. Only change, you will have to do in the above query is so change user_tab_columns to all_tab_columns and add the OWNER predicate respectively with the clause.

  • Need help with the query to get the County

    Hello

    Oracle 10 g 2 10.2.0.3 - 64 bit

    I want back the number of accounts with two different types of funds (say A and B). Some accounts hold only one of the two funds, and some support both. I want to get the counts like this:

    • account held funds - has only
    • accounts holding funds-B only
    • accounts holding the Fund-A and B funds

    Here is what I started with but need assistance to meet the requirement above:

    select 
    count(distinct acct.bkoff_acct_no ) accounts_holding_fund_A
    from xe_account acct,
            xec_tal_investment_mandate iman,
            xec_tal_asset_allocation alloc,
            xe_benchmark bmark,
            xe_benchmark_usage bu,
            xe_object_description xod,
            xec_asset_class cls
    where iman.mandate_status_cd='A'
    and cls.asset_class_cd = alloc.asset_class_cd
    and iman.mandate_id = alloc.mandate_id
    and acct.account_id = iman.object_id
    and iman.object_type_cd = 'ACCT'
    and iman.mandate_id = xod.object_id
    and xod.field_nm='XEC_TAL_INVESTMENT_MANDATE.COMMENT_TXT'
    and xod.language_cd = 'E'
    and acct.acct_status_cd = 'O'
    and bu.object_type_cd(+) = 'TMAA'
    and bu.object_id(+) = alloc.asset_allocation_id
    and bmark.benchmark_id(+) = bu.benchmark_id
    and alloc.resp_txt like '%fund-A%'
    
    
    

    And suppose that the Fund-B has resp_txt like ' % of Fund-B»

    Please suggest.

    Concerning

    Hello

    Here is another way, it is easier to adapt to different jobs and different numbers of jobs:

    WITH got_distinct_jobs AS

    (

    SELECT DISTINCT deptno, job

    FROM scott.emp

    WHERE job IN ("ANALYST", "CLERKS") - or what

    )

    got_job_list AS

    (

    SELECT LISTAGG (job, ",") THE Group (ORDER BY work) AS job_list

    OF got_distinct_jobs

    GROUP BY deptno

    )

    SELECT job_list

    COUNT (*) AS num_departments

    OF got_job_list

    GROUP BY job_list

    ;

    This shows all the combinations of the jobs listed in the WHERE clause of got_distinct_jobs.  You don't need to change anything else in the query.  There may be any number of jobs.

    Output:

    JOB_LIST NUM_DEPARTMENTS

    ------------------------------ ---------------

    CLERK                                        2

    ANALYST, CLERK 1

  • SQL query to get the number of days monthwise

    Hello
    I'm new to sql, can someone please tell me query to find the number of days between the two dates months wise.
    say
    FIRSTDATE last date
    21/03/2011-25/06/2011

    March April May June
    9 22 23 18

    Hello

    Welcome to the forum!

    Here's one way:

    WITH     all_dates     AS
    (
         SELECT     start_date + LEVEL - 1     AS a_date
         FROM     (
                   SELECT     TO_DATE ('21/03/2011', 'DD/MM/YYYY')     AS start_date
                   ,     TO_DATE ('25/06/2011', 'DD/MM/YYYY')     AS end_date
                   FROM     dual
              )
         CONNECT BY     LEVEL     <= end_date + 1 - start_date
    )
    SELECT       TO_CHAR ( TRUNC (a_date, 'MONTH')
                , 'fmMonth YYYY'
                )               AS month
    ,       COUNT (*)               AS num_days
    FROM       all_dates
    WHERE       a_date - TRUNC (a_date, 'IW')     < 5
    GROUP BY  TRUNC (a_date, 'MONTH')
    ORDER BY  TRUNC (a_date, 'MONTH')
    ;
    

    What is a 'working day '? I guess you mean every day except Saturday or Sunday, but the query aboveare sometimes figures less than you have asked:

    MONTH             NUM_DAYS
    --------------- ----------
    March 2011               9
    April 2011              21
    May 2011                22
    June 2011               18
    

    Are a few days working on Saturday or Sunday? How do you get the 22 working days in April 2011 and 23 in may?

    SQL is good at obtaining results with a variable number of rows, but you have to say exactly the desired number of columns when you write the query.
    If you really need the output of the way you said, with any number of columns, then watch in swing or a grouping of the chain . See the FAQ forum
    https://forums.Oracle.com/forums/Ann.jspa?annID=1535
    "4. How can I convert rows to columns.

  • Query to get the date from

    Hello everyone,

    How can I create a query having 2 date and 2 variable of the type:
    from 1 date 05/06/2004 
    to   2 date 15/06/2004 
    yes for 2 days
    no for  1 day
    that is, 
    
    i wish get the date with yes for 2 days and not for 1 day, this is, that I want
    
    05/06/2004 sabato
    06/06/2004 domenica
    08/06/2004 martedì
    09/06/2004 mercoledi
    11/06/2004 venerdi
    12/06/2004 sabato  
    14/06/2004 lunedi
    15/06/2004 martedi
    Thanks in advance

    Hello

    The WHERE clause controls the lines will appear.
    If your needs change, change the WHERE clause to reflect their.

    For example:

    DEFINE     from_date     = "TO_DATE ('05/06/2004', 'DD/MM/YYYY')"
    DEFINE     to_date          = "TO_DATE ('15/06/2004', 'DD/MM/YYYY')"
    DEFINE     yes_cnt          = 3
    DEFINE     no_cnt          = 2
    
    SELECT  &from_date + LEVEL - 1        AS dt
    FROM     dual
    WHERE     MOD ( LEVEL
             , &yes_cnt + &no_cnt
             )          BETWEEN  1
                       AND      &yes_cnt
    CONNECT BY  LEVEL <= 1 + &to_date
                         - &from_date
    ORDER BY  dt;
    

    This will work as long as you want the first & yes_cnt lines to display (assuming that there are many) and the following lines & no_cnt don't step to display, and then another & yes_cnt lines to display and the other & no_cnt lines not to display and so on.

    I guess & yes_cnt is a positive integer and that & no_cnt is a non-negative integer. (I.e. & no_cnt can be 0)

  • Query to get the units of capital fixed for the period?

    Hi all

    I'm building a report in capital in Oracle Apps R12.

    Since a few days I'm fighting with units of query. I'm not able to get the correct units for the period.

    An asset can have several scenarios such as partial retirement, full retirement, transfer, partial transfer, camera settings full reintegration... etc.

    So anyone who has an idea about this?

    Each kindly do the needful.

    Station pl in Navision Financials

  • Query to get the flex field values description.

    Hello

    Entering invoices-> all the Distributions screen 'Special Mentions for the India' is here. Here we enter the value for the field TDS - tax. I want to get the list of values for TDS - tax in a query.

    Can you please help me.

    Thank you

    Nanga.

    where 'jtc.tax_type =' TDS

    and jtc.section_type = 'TDS_SECTION. '

    and org_id =: inv_sum_folder.org_id

    and jtc.section_code in

    (

    Select section_code

    of jai_ap_tds_th_vsite_v

    where vendor_id =: inv_sum_folder.vendor_id

    and vendor_site_id =: inv_sum_folder.vendor_site_id

    )

    order of jtc.tax_id

  • Analysis of query and get the list of used tables

    Hi all

    I need to parse the sql query (simple & complex as well) and for a list of the tables used in the query.

    And need to validate the fact that list the tables against a whitelist that is kept in the file.

    I tried to write my own parser, because there are many ways to write complex queries, I'm unable to cover all scenarios.

    I need help, is there other ways to get the list of tables used in a query?

    Thank you

    Manon...

    In general you would add a condition 1 = 2 just to restrict the display of the entire table. Then should not be causing any noticeable performance degradation. You can even use ROWNUM< 2.="" that="" will="" do="" a="" count="" stopkey.="" which="" could="" be="">

    SQL > select * from emp where rownum<>

    no selected line

    SQL > select * from table (dbms_xplan.display_cursor);

    PLAN_TABLE_OUTPUT
    --------------------------------------------------------------------------------
    SQL_ID, 97f4bd002xfy0, number of children 0
    -------------------------------------
    Select * from emp where rownum<>

    Hash value of plan: 4269703525

    ---------------------------------------------------------------------------
    | ID | Operation | Name | Lines | Bytes | Cost (% CPU). Time |
    ---------------------------------------------------------------------------
    |   0 | SELECT STATEMENT |      |       |       |     2 (100) |          |
    |*  1 |  COUNT STOPKEY |      |       |       |            |          |
    |   2.   TABLE ACCESS FULL | EMP |     1.    38.     2 (0) | 00:00:01 |
    ---------------------------------------------------------------------------

    Information of predicates (identified by the operation identity card):
    ---------------------------------------------------

    1 Filter (ROWNUM<>

    19 selected lines.

    But its always good to bench mark it yourself.

  • Query to get the difference between 2 totals of 2 different queries

    I wanted to know if it is possible to get the difference between 2 totals of 2 different queries. Let me explain with an example:

    1 application ofst - sum (homepass) Select table 1

    2th query: select sum (homepass) from table2

    Is it possible to display the difference as -

    Select sum (homepass) in table 1 - sum (homepass) from table2

    I know that the above query would give syntax error, but is there a better way or something to get the above done task from a single query.


    Hopefully, my question is clear.


    Please get back with the answer to my query.


    Concerning

    You can always do something like

    SELECT a.cnt - b.cnt
    FROM (SELECT sum(homepass) cnt from table1) a,
          (SELECT sum(homepass) cnt from table2) b
    

    I'd be somewhat dubious, although on a data model that had two tables with the same name of the column where it really made sense to subtract one amount from each other.  This would strongly imply that there should be a single table with an additional column TYPE eventually.

    Justin

  • Query to get the time MIN

    Hi all.

    How can I get rank with MIN time (DESPITE DAY) (for the first six hours 08:00-14:00, AND the NEXT 6 hours 14:01 to 20:00)
    If what follows is my sample
    03/05/2012 17:30:00
    04/05/2012 17:00:00
    10/05/2012 18:00:00
    12/05/2012 08:00:00
    10/05/2012 07:00:00  
    03/05/2012 11:00:00  
    my result should be at first six hours 07:00 and 17:00 followed by six)


    Thanks in advance for any help

    Personally, I do not like to convert dates into strings and vice versa. I think that both arithmetic and precise the date date would perform better.

    Here's an alternative:

    with t as (
      select to_date('03/05/2012 17:30:00','DD/MM/YYYY HH24:MI:SS') as dt from dual union all
      select to_date('04/05/2012 17:00:00','DD/MM/YYYY HH24:MI:SS') from dual union all
      select to_date('10/05/2012 18:00:00','DD/MM/YYYY HH24:MI:SS') from dual union all
      select to_date('12/05/2012 09:00:00','DD/MM/YYYY HH24:MI:SS') from dual union all
       select to_date('10/05/2012 08:30:00','DD/MM/YYYY HH24:MI:SS') from dual union all
      select to_date('03/05/2012 11:00:00','DD/MM/YYYY HH24:MI:SS') from dual
    )
    select to_char(min(dt) keep (dense_rank first order by dt-trunc(dt)), 'HH24:MI:SS') hh24miss
    from t
    group by trunc((extract(hour from to_timestamp(dt))-2)/6)
    order by 1;
    
    HH24MISS
    --------
    08:30:00
    17:00:00
    

    Explanation:

    -Use the EXTRACT function to get the time. The date must be "converted" in a timestamp date because ANSI does not have the component "hour".
    -Subtract the difference of two hours from the time. This will change the interval from 2-8 to 0-6, 8-14-6-12, etc.
    -Divide by 6 and truncates the result. This will give 1 what it is from 08:00 to 13:59.59 hours.
    -Group by this result, which will all split into groups of ranges of 6 hours.

    -Now, in each group, so the component "hour": TRUNC (DT) is the date with time set to 0, DT - TRUNC (DT) is the component "hour".
    -Ordering by the component "hour", download the first date that corresponds to the first component of the time.

    Published by: stew Ashton on November 16, 2012 17:38

  • Query to get the total counts in the given scenario

    Hello

    I use Oracle 10 g

    I have a table with the following data

    AgId Trm CD S
    -------------------------------------------------
    A 1000 100010, 12 - JAN
    A 1000 100019, 20 - MAR
    1000 100019 D 20-JUL
    -------------------------------------------------
    1001 100011 25-JAN HAS
    1001 100011 D 20 - FEB
    A 1001 100011, 23 - MAR
    1001 100012 A 31 - JAN
    -------------------------------------------------
    1002 100013 A 14 - FEB
    D 1002 100013 05 - APR
    1002 100015 02-MAY HAS
    -------------------------------------------------
    A 1003 100014, 03 - MAR
    1003 100014 D 25 - MAR
    -------------------------------------------------
    1004 100016 HAS 22 - MAY
    1004 100017 21 - JUN HAS
    A 1004 100018, 01 - JULY
    -------------------------------------------------
    1005 100020 D 21-MAY
    1005 100020 HAS 21-JUL
    1005 100020 D 11 - AUG

    Here the overall status of AgId '1000' is A as it is to have at least 1 active Trm
    Similarly, the status of AgId '1001' is A
    status of AgId '1002' is A
    But, the AgId '1003' is D its CRT is disconnected after activation (according to the date column 'CD')
    Then, the status of AgId '1004' is A
    and finally AgId '1005' is new D as its CRT disabled, active and disabled finally

    Therefore, taking into account these criteria can someone give me a query to get (not AgId, who are 'Assets') and similarly 'disabled '.

Maybe you are looking for

  • iTunes does not see iPhone 5 s after installing iOS 10

    Update wireless phone.  Everything went well.  I connect the iPhone to Mac (10.7.5) and Capture of Image asked me to unlock the phone.  It's unlocked, but he asks again. iTunes displays an error: I changed the data cables using apple and 3rd same par

  • Re: BSOD play WoW on Satellite A300

    I played WoW yesterday and my computer froze. (This is the first time, it never happened) After that I reset the phone and scanned computer for a virus and didn't find any.Connected to the net and has started again, playing about 20 minutes later, it

  • How can I change the default 'from' address in iCloud/Apple Mail

    I changed it to a point to my alias iCloud, and no matter how many times I change it in Apple Mail preferences it does not stick. When I close my iMac down, the next time I start up my alias address you "from" still my default address once. V. frustr

  • My ts-tb23l hp dvdwbd dvd drive won't recognise dvd-video.

    I have a hp Touchsmart 610 with windows 7 and the dvd player does not read video however it will play music. HP 610-1020 a TouchSmart desktop PC.  any ideas on why this is. brand new unit.

  • Windows Vista Edition upgrade Home Premium to Windows 7 Professional

    Hi!, I need help.  I tried to understand the upgrade from Windows Vista to Windows 7 but I have not been able to fully understand the various issues.  My dilemma is this. I have a House runing PC with Windows Vista Home Premium and I want to install