Group records between trade unions

Gurus,

It's been a while since I formatted in SQL, but I have developed the following query, which gives me the result below:
     select distinct created_by, count(created_by) receipt_count,  null deliver_count
     from  wms_transaction
     where creation_date > sysdate-10
     and   transaction_type = 'RECEIPT'
     group by  created_by
   union
     select distinct created_by,  null rec_count,  count(created_by) deliver_count
     from  wms_transaction
     where creation_date > sysdate-10
     and   transaction_type = 'DELIVER'
     group by created_by   
     order by receipt_count

CREATED_BY    RECEIPT_COUNT     DELIVER_COUNT
--------------------   -----------------------     ------------------------
SPRECKO                    4
HKUMAR                     4
SPRECKO                                            10
HKUMAR                                           856
The desired output is a user consolidated without additional records...
CREATED_BY    RECEIPT_COUNT     DELIVER_COUNT
--------------------   -----------------------     ------------------------
SPRECKO                    4                       10
HKUMAR                     4                     856
Someone there all of the recommendations? I give the points to obtain useful and accurate responses (someone always comments on the points system when I write that ;-))

Thank you
Scott

Published by: sreese on April 25, 2013 14:23

Published by: sreese on April 25, 2013 14:23

Hello

You can do it with a pivot:

select    created_by
,        count ( CASE
                  WHEN  transaction_type = 'RECEIPT'
                THEN  created_by
            END
          )     as receipt_count
,        count ( CASE
                  WHEN  transaction_type = 'DELIVER'
                THEN  created_by
            END
          )     as deliver_count
from      wms_transaction
where        creation_date    > sysdate - 10
and          transaction_type IN ('DELIVER', 'RECEIPT')
group by  created_by
;

It will be much more effective than a UNION.

The query above works in Oracle 8.1 or more. From Oracle 11, you can also use SELECT... PIVOT.

I hope that answers your question.
If not, post a small example data (CREATE TABLE and only relevant columns, INSERT statements) and also publish outcomes from these data.
Explain, using specific examples, how you get these results from these data.
Always say what version of Oracle you are using (for example, 11.2.0.2.0).
See the FAQ forum {message identifier: = 9360002}

Published by: Frank Kulash on 25 April 2013 14:37

Tags: Database

Similar Questions

  • How to filter records in a UNION ALL query

    Hi all

    I have only one requirement to filter records in a query UNION all. If we do not all matching records to one of the union, all question them.

    create table test_1(n1 number,n2 number,n3 number)
    
    insert into test_1 values(1,2,3);
    insert into test_1 values(11,22,33);
    insert into test_1 values(55,66,77);
    
    Case-1 :
    
    SELECT N1,N2,N3
    FROM TEST_1
    WHERE N2=2
    UNION ALL
    SELECT N1,N2,N3
    FROM TEST_1
    WHERE N3=3
    
    Output is : This is desired output(so we are good)
    
    1,2,3
    1,2,3
    
    Case 2 :
    
    SELECT N1,N2,N3
    FROM TEST_1
    WHERE N2=22
    UNION ALL
    SELECT N1,N2,N3
    FROM TEST_1
    WHERE N3=44
    
    Output : (Here is the problem: If we don't have matching records for anyone union all query we don't want any records)
    
    Output is coming : 11,22,33
    
    Out put : No Records (We want this output.)
    

    I hope I have given the clear example of my requirement.

    Thank you.

    with

    test_1 as

    (select 1 n1, n2 2, n3 3 of all the double union)

    Select 11,22,33 from all the double union

    Select double 55,66,77

    )

    Select the n1, n2, n3

    from (select n1, n2, n3

    of test_1

    where n2 =: n2

    Union of all the

    Select the n1, n2, n3

    of test_1

    where = n3: n3

    )

    where exists (select null from test_1 where n2 =: n2)

    and it exists (select null from test_1 where = n3: n3)

    Concerning

    Etbin

  • Count the number of records between two values of keys (BTREE)

    How can I count the number of keys between two values?

    I use python driver and BTREE access method.

    = >

    Ideally, what I want is a set of whole time series data (intervals may change) to a given number of points on average. The keys are timestamps and the values are the data that it takes on average. I need to count the number of records between two timestamps so that I can divide this figure by the number of points I need and data on average. What is the best way to do it?  Or should I keep the timestamp constant intervals and use the RECNO access method?

    Thank you
    (first post btw... and why is there not a lot of people at stackoverflow that answering the questions of Berkeley DB?)

    BDB is an integrated db and there no internal counters or statistics you might grap to use for this.    You will have to do it manually.

    You can create a cursor, grap the records you want, whenever you get the next card that you bump a counter.

    If you are using RECNO, you can use a slider to obtain the number of registration (DB_GET_RECNO), and if all that you data is in

    sequentail records with no missing documents, you can find the total number of take the last rec #-original rec # + 1 to get a count.

    If you pass the SQL API, you can issue a SQL query to give you a count.  Select count (*) where...

    As you enter the data anyway, so better perhaps to count records as you go along.

    Thank you

    Mike

  • Get records between two Dates

    Hello

    I have my structure of the table and records build here
    http://sqlfiddle.com/#! d099ef/4/7

    I would like to get the records between two dates.
    For example, I would get the records between October 1, 2001 and October 31, 2001.

    How can I get the records. Any help is much appreciated.

    Concerning

    Published by: ponic on 29 August 2012 09:42

    ponic says:

    Start       End
    4th Jul    12th Dec
    4th Jul    10th Oct
    3rd Oct   19th Nov
    3rd Oct   4th Oct
    

    I would like to have all the lines between October 1, 2001 and October 31, 2001
    If the above lines because every OCTOBER under the foregoing.

    Thank you

    Try

    select *
    from products_range
    where product_start_date <= to_date('31-oct-2001', 'dd-mon-yyyy')
    and product_end_date >= to_date('1-oct-2001', 'dd-mon-yyyy')
    

    Published by: Paul Horth on August 29, 2012 00:46

  • SQL to group records and apply logic to pick up a record of each group

    Hi friends,

    I am looking for a query group records on some columns in a table and then each group I want to take just a single folder according to certain rules.

    Could have given arranged at will to make my point more clear for you. Here you go:
    CREATE TABLE AD_LIST
    (
      FILE_NAME             VARCHAR2(50 BYTE),
      ACTIVITY_START        DATE,
      ACTIVITY_END          DATE,
      DIVISION              VARCHAR2(50 BYTE),
      ITEM_CODE             VARCHAR2(50 BYTE),
      MULT                  NUMBER,
      RETAIL                NUMBER,
      AD_PAGE               VARCHAR2(1 BYTE),
      FORECAST              NUMBER,
      MEMO                  VARCHAR2(50 BYTE)
      );
    
    INSERT INTO AD_LIST VALUES ('FILE_1','01-APR-2010','15-APR-2010','B',1111,5,10,'A',10,'This must be in my result');
    INSERT INTO AD_LIST VALUES ('FILE_1','01-APR-2010','15-APR-2010','B',1111,1,1,'B',15,'Must not be in my result');
    INSERT INTO AD_LIST VALUES ('FILE_1','01-APR-2010','15-APR-2010','B',1111,6,15,'C',11,'Must not be in my result');
    
    INSERT INTO AD_LIST VALUES ('FILE_1','16-APR-2010','30-APR-2010','N',1111,4,20,'D',40,'Must not be in my result');
    INSERT INTO AD_LIST VALUES ('FILE_1','16-APR-2010','30-APR-2010','N',1111,5,15,'E',30,'Must not be in my result');
    INSERT INTO AD_LIST VALUES ('FILE_1','16-APR-2010','30-APR-2010','N',1111,1,2,'F',20,'This must be in my result');
    
    CREATE TABLE PAGE_RANK
    (
      AD_PAGE VARCHAR2(1 BYTE),
      RANK NUMBER
    );
    
    INSERT INTO PAGE_RANK VALUES ('A',1);
    INSERT INTO PAGE_RANK VALUES ('B',2);
    INSERT INTO PAGE_RANK VALUES ('C',3);
    INSERT INTO PAGE_RANK VALUES ('D',4);
    INSERT INTO PAGE_RANK VALUES ('E',5);
    INSERT INTO PAGE_RANK VALUES ('F',6);
    COMMIT;
    
    SELECT * FROM AD_LIST
    
    FILE     ACTIVITY     ACTIVITY          ITEM               AD
    NAME     START          END          DIV     CODE     MULT     RETAIL     PAGE     FORECAST     MEMO
    -----     --------     ---------     ---     ----     ----     -----     ----     ------     -----------------------     
    FILE_1     4/1/2010     4/15/2010     B     1111     5     10     A     10     This must be in my result
    FILE_1     4/1/2010     4/15/2010     B     1111     1     1     B     15     Must not be in my result
    FILE_1     4/1/2010     4/15/2010     B     1111     6     15     C     11     Must not be in my result
    FILE_1     4/16/2010     4/30/2010     N     1111     4     20     D     40     Must not be in my result
    FILE_1     4/16/2010     4/30/2010     N     1111     5     15     E     30     Must not be in my result
    FILE_1     4/16/2010     4/30/2010     N     1111     1     2     F     20     This must be in my result
    Now, the AD_LIST table I want to group records based on FILE_NAME, ACTIVITY_START, ACTIVITY_END, DIVISION, ITEM_CODE.
    So, in my example here, we have 2 grouped recordset based on the specified columns.

    Also, we have a table, PAGE_RANK, who has a rank corresponding to each issue of ad_page. 1. This is a rank higher than 2. This is why page ad 'A' takes precedence over 'B '. The same for all the other pages of ads.

    Now, we need to choose an announcement of each ad group in determining page ad rank higher within the Group and the value of mult and retail should be replaced by the value that has min(retail/mult). So, using the above data we will have with the full-page ad = 'A' and ad = page had ' as final results since they have the highest grade of advertising page in their group.
    The value of values mult and details of ad_page 'A' = min (10/5, 1/1, 15/6) = 1,1(mult,retail).
    The value of values mult and detail of ad_page would be ' = min (20/4, 15/5, 2/1) = 1,2(mult,retail).

    Finally I have this query below
    SELECT a.file_name,
           a.activity_start,
           a.activity_end,
           a.division,
           a.item_code,
           FIRST_VALUE (a.mult) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (a.retail /
                                                                                                                                    a.mult))
                                                                                                        mult,
           FIRST_VALUE (a.retail) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (a.retail /
                                                                                                                                      a.mult))
                                                                                                      retail,
           FIRST_VALUE (a.ad_page) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (b.RANK))
                                                                                                     ad_page,
           a.forecast,
           a.memo                                                                                                 
      FROM ad_list a, page_rank b
     WHERE a.ad_page = b.ad_page
    This query is giving me all the records, but with the values of what I wanted in the columns Ad_Page, Mult, and retail.
    How can I take only one of each group.

    I get this
    FILE     ACTIVITY     ACTIVITY          ITEM               AD
    NAME     START          END          DIV     CODE     MULT     RETAIL     PAGE     FORECAST     MEMO
    -----     --------     ---------     ---     ----     ----     -----     ----     ------     -----------------------     
    FILE_1     4/1/2010     4/15/2010     B     1111     1     1     A     15     Must not be in my result
    FILE_1     4/1/2010     4/15/2010     B     1111     1     1     A     10     This must be in my result
    FILE_1     4/1/2010     4/15/2010     B     1111     1     1     A     11     Must not be in my result
    FILE_1     4/16/2010     4/30/2010     N     1111     1     2     D     20     This must be in my result
    FILE_1     4/16/2010     4/30/2010     N     1111     1     2     D     30     Must not be in my result
    FILE_1     4/16/2010     4/30/2010     N     1111     1     2     D     40     Must not be in my result
    But I want this
    FILE     ACTIVITY     ACTIVITY          ITEM               AD
    NAME     START          END          DIV     CODE     MULT     RETAIL     PAGE     FORECAST     MEMO
    -----     --------     ---------     ---     ----     ----     -----     ----     ------     -----------------------     
    
    FILE_1     4/1/2010     4/15/2010     B     1111     1     1     A     10     This must be in my result
    FILE_1     4/16/2010     4/30/2010     N     1111     1     2     D     20     This must be in my result
    I have to run this query for thousands of such combination of group.
    Hope someone can shed some light on this query.

    Thanks in advance,
    Raj.

    Hello

    This is called a Query Top - N .

    How do you determine which line of each group you want to display?
    If this is the line with forecasts as low, then:

    WITH   got_r_num     AS
    (
    SELECT a.file_name,
           a.activity_start,
           a.activity_end,
           a.division,
           a.item_code,
           FIRST_VALUE (a.mult) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (a.retail /
                                                                                                                                    a.mult))
                                                                                                        mult,
           FIRST_VALUE (a.retail) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (a.retail /
                                                                                                                                      a.mult))
                                                                                                      retail,
           FIRST_VALUE (a.ad_page) OVER (PARTITION BY a.file_name, a.activity_start, a.activity_end, a.division, a.item_code ORDER BY (b.RNK))
                                                                                                     ad_page,
           a.forecast,
           a.memo,
           ROW_NUMBER () OVER ( PARTITION BY  a.file_name
                                   ,                  a.activity_start
                       ,            a.activity_end
                       ,            a.division
                       ,            a.item_code
                       ORDER BY       a.forecast
                     )      AS r_num
      FROM ad_list a, page_rank b
     WHERE a.ad_page = b.ad_page
    )
    SELECT file_name,
           activity_start,
           activity_end,
           division,
           item_code,
           forecast,
           mult,
           retail,
           ad_page,
           memo
    FROM   got_r_num
    WHERE  r_num     = 1
    ;
    

    If it is something else, then change the ORDER BY clause in the ROW_NUMBER function.

  • Findout incompatibility records between the two tables.

    I need help on findout the unmatched records between two different tables.

    Each table has a + 42Crores Records.

    The type of data (Char) are the same for the two tables but datalength is different between a table and the table B.

    Indexes are created on the two tables on the required fields

    There is no Geom data exists on the two tables.



    For example:

    A Table: =.
    Number of records + 42Crores
    Rating: TOLD char (20)

    Table B: =.
    Number of records + 42Crores
    Field: TOLD Char (16)

    I took individual accounts, there are number of difference is 3868 only, with respect to the count (*) selection.

    I ran the query "Select TOLD OF A LESS SELECT TOLD OF B", but I don't have the answer.

    Please let me know how to solve the problem.

    The variable length char shouldn't be a problem...
    You just need to ensure that the first table has more lines than the second, if the problem persists You ' l I hide it, and then use a column alias...

    Let know us...

  • selection of the missing records between 2 duplicity without worrying about tables of records

    Hi all

    I have received_bills and send_bills of 2 tables.

    The SEND_BILLS table is the source table displaying all records in it.

    I need to compare two tables together and insert all the missing elements in received_items including duplicate records.

    There may be duplicate in 2 tables records.

    I wrote a query, but it does not select the duplicate records if it's all the 2 tables. When the same duplicate records are send_bills and received_bill without worrying because send_bills has 4 of them and received_bill 2, it does not select the other 2 duplicate records. And it's just what I need.

    the query is

    SELECT SEND. POINT OF REFERENCE,

    Send. PAYMENT,

    Send. CODE

    OF SEND_BILLS SEND

    WHERE THERE IS NOT (SELECT REC. DATUM, PAYMENT, REC. REC. CODE

    OF RECEIVED_BILLS REC

    WHERE REC. REFERENCE = SEND. SCRATCH CARDS

    AND REC. PAYMENT = SEND. PAYMENT

    AND REC. CODE = SEND. CODE)

    send_bills records

    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1529A3
    OCTOBER 10, 1547A4
    9 OCTOBER 1519A8
    OCTOBER 10, 1520A1
    OCTOBER 10, 1519A1
    OCTOBER 10, 1525A5
    OCTOBER 10, 1525A5

    received_bills records

    OCTOBER 10, 1519A1
    OCTOBER 10, 1529A3
    OCTOBER 10, 1547A4
    OCTOBER 10, 1519A1

    the result of the query is:

    OCTOBER 10, 1525A5
    OCTOBER 10, 1525A5
    OCTOBER 10, 1520A1
    9 OCTOBER 1519A8

    So he selects all the records

    the result should be

    OCTOBER 10, 1525A5
    OCTOBER 10, 1525A5
    OCTOBER 10, 1520A1
    9 OCTOBER 1519A8
    OCTOBER 10, 1519A1
    OCTOBER 10, 1519A1

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

    -The DOF for Table SEND_BILLS

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

    CREATE TABLE SEND_BILLS

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE)

    )  ;

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

    -The DOF for Table RECEIVED_BILLS

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

    CREATE TABLE 'RECEIVED_BILLS '.

    (DATE OF "DATUM",

    NUMBER OF "PAYMENT."

    'CODE' VARCHAR2 (5 BYTE)

    )  ;

    -Insert the script for send_bills

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 29, 'A3');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('09-OCT-15','DD-MON-RR'), 19, 'A8');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 20, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5')

    Insert into SEND_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 25, 'A5')

    -Insert invoices received from script

    Insert into RECEIVED_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Insert into RECEIVED_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 29, 'A3');

    Insert into RECEIVED_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 47, 'A4');

    Insert into RECEIVED_BILLS (DATUM, CODE) values (to_date('10-OCT-15','DD-MON-RR'), 19, 'A1');

    Can someone please help me with the query so that I can also select all the missing records, including duplicates.

    Thanks in advance.

    Best regards

    Caroline

    If you should by all means use loop and then (send_bills and received_bills contain the same data as your original post):

    Select the reference, payment, code

    of (with

    Duplicator (Datum, Payment, code, CNT) as

    (select the reference, code, payment, cnt - 1).

    from (select datum, payment, code, count (one) - cnt count (two)

    (select date, payment, code, 1 one, to_number (null) two)

    of send_bills

    Union of all the

    Select datum, payment, code, to_number (null), 2 two

    of received_bills

    )

    Reference group, code

    having count (one)! = count (two)

    )

    Union of all the

    Select the reference code, payment, cnt - 1

    The duplicator

    where cnt > 0

    )

    Select the reference, payment, code

    The duplicator

    )

    DATUM PAYMENT CODE
    10/09/2015 19 A8
    10/10/2015 19 A1
    10/10/2015 25 A5
    10/10/2015 20 A1
    10/10/2015 19 A1
    10/10/2015 25 A5

    Concerning

    Etbin

  • FILL MONTHS DYNAMICALLY IN THE ITEM VIA ORACLE FORMS GROUP RECORDING LIST

    Experts

    I have a query in oracle forms. I need to fill Last_Month, Current_Month & Next_month based on Sys_Date in the list box. I am able to get the values in SQL if I run the query below, but when I use the version of Oracle Forms 10.1.2.0.2, I could not get the values of Mr. can you please guide me where I'm wrong.

    declare

    v_rg_id recordgroup: = NULL;

    Number of V_errorcode;

    v_rg_salmth varchar2 (30): = "MONTHS";

    Begin

    v_rg_id: = find_group (v_rg_salmth);

    If id_null (v_rg_id) then

    v_rg_id: = create_group_from_query (v_rg_salmth,

    "WITH (AS MONTH_COUNTER)

    SELECT LEVEL 2 AS ID

    OF THE DOUBLE

    CONNECT BY LEVEL = 2

    UNION

    SELECT LEVEL AS ID

    OF THE DOUBLE

    CONNECT BY LEVEL = 0

    )

    SELECT TO_CHAR (ADD_MONTHS (TO_CHAR (SYSDATE), ID), MONTH) AS MONTH_COUNTER MONTHS ');

    v_errorcode: = populate_group (v_rg_id);

    If v_errorcode = 0 then

    message ("record group filled with data");

    on the other

    message ("V_errorcode is:" | ") v_errorcode);

    end if;

    End if;

    populate_list('MASTER.) MONTH, v_rg_id);

    end;

    The rather complicated query, try

    SELECT ADD_MONTHS (SYSDATE-1) TO DOUBLE

    UNION ALL

    SELECT SYSDATE DOUBLE

    UNION ALL

    SELECT THE DOUBLE ADD_MONTHS(SYSDATE,1)

    BTW. to use a query to populate a list, you must select two values, a label and a value, check it fill listitems dynamically - Andreas Weiden - on Oracle

  • Group records as well as frequent mailers

    Hi people,

    I'm looking at a scenario where I would like to group the dates together (for the most part, we assume they are similar and close enough dates and so probably on the same date) when they are close together. The idea is to eliminate the possible duplicates.

    Create table scripts and INSERT into the table:

    create table orders_tb (order_id varchar2(4), order_date date);
    
    insert into orders_tb (order_id,order_date) values ('1001',to_date('31-DEC-13','DD-MON-RR'));
    insert into orders_tb (order_id,order_date) values ('1001',to_date('02-JAN-14','DD-MON-RR'));
    insert into orders_tb (order_id,order_date) values ('1001',to_date('06-JAN-14','DD-MON-RR'));
    insert into orders_tb (order_id,order_date) values ('1001',to_date('12-JAN-14','DD-MON-RR'));
    insert into orders_tb (order_id,order_date) values ('1002',to_date('02-FEB-14','DD-MON-RR'));
    insert into orders_tb (order_id,order_date) values ('1002',to_date('02-MAR-14','DD-MON-RR'));
    insert into orders_tb (order_id,order_date) values ('1002',to_date('02-MAR-14','DD-MON-RR'));
    

    If I ran the following SELECT statement, I would get 6 entries:

    select distinct order_id, order_date from orders_tb order by order_id, order_date;
    

    However, for the most part, I would like to Order ID 1001 subject only two records. The rule for including dates, that is all the dates to be within 10 days of the date of MIN.

    1001 31-DEC-2013
    1001 12-JAN-2014
    

    Regarding the command ID 1002, he will tell you that the dates are very far.

    1002 02-FEB-2014
    1002 02-MAR-2014
    

    Any help would be greatly appreciated.

    Thank you!

    Hello

    You want to always 2 rows for each order_id exit or you want sometimes 1 or 3 or more?

    You can test it with a little more data sample that test situations like these.  For example, in addition to the sample data that you posted:

    insert into orders_tb (order_id, order_date) values ('1001 ', to_date('13-JAN-2014','DD-MON-YYYY'));

    insert into orders_tb (order_id, order_date) values ('1001 ', to_date('19-JAN-2014','DD-MON-YYYY'));

    insert into orders_tb (order_id, order_date) values ('1001 ', to_date('25-JAN-2014','DD-MON-YYYY'));

    insert into orders_tb (order_id, order_date) values ('1003 ', to_date('01-JAN-2014','DD-MON-YYYY'));

    insert into orders_tb (order_id, order_date) values ('1003 ', to_date('10-JAN-2014','DD-MON-YYYY'));

    Here's one way:

    WITH got_next_date AS

    (

    SELECT DISTINCT

    order_id, order_date

    MIN (order_date) over (PARTITION BY order_id) AS start_date

    MIN (order_date) over (PARTITION BY order_id

    ORDER BY order_date

    RANGE BETWEEN 10.000001 MORE

    AND UNBOUNDED FOLLOWING

    ), Next_date

    Of orders_tb

    )

    SELECT order_id, order_date

    OF got_next_date

    START WITH order_date = start_date

    CONNECT BY order_date = next_date PRIOR

    AND order_id = order_id PRIOR

    ;

    Output (including the sample data, I added):

    ORDER_ID, ORDER_DATE

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

    1001 December 31, 2013

    1001 12 January 2014

    1001 January 25, 2014

    1002 February 2, 2014

    1002 2 March 2014

    1003 1 January 2014

  • Grouping records

    Hi all

    I have this table
    WITH taba
            AS (SELECT   83573 AS id, 135433 AS pe_rule_id, 46493 AS uc_id
                  FROM   DUAL
                UNION ALL
                SELECT   83574 AS id, 135433 AS pe_rule_id, 46512 AS uc_id
                  FROM   DUAL
                UNION ALL
                SELECT   83557 AS id, 137004 AS pe_rule_id, 47277 AS uc_id
                  FROM   DUAL
                UNION ALL
                SELECT   83558 AS id, 139647 AS pe_rule_id, 47277 AS uc_id
                  FROM   DUAL
                UNION ALL
                SELECT   83571 AS id, 144804 AS pe_rule_id, 46493 AS uc_id
                  FROM   DUAL
                UNION ALL
                SELECT   83572 AS id, 144804 AS pe_rule_id, 46512 AS uc_id
                  FROM   DUAL)
    SELECT   *
      FROM   taba
    I need to get all records with MIN (ID), that have the same group uc_id records.
    Return:
    135433 46493
    46512 135433
    137004 47277

    For example, 2 = 144804 pe_rule_id records have both the same uc_id as the chronogram pe_rule_id = 135433 2. In this case, I need only the records pe_rule_id = 135433

    This is just one example. I may have records with 3 or more uc_id diferent to the same pe_rule_id.

    Can you help me please?
    Thank you

    Filipe Almeida

    Do you mean min (pe_rule_id)?

    Like this?

    SQL> ed
    Wrote file afiedt.buf
    
      1  WITH taba
      2          AS (SELECT   83573 AS id, 135433 AS pe_rule_id, 46493 AS uc_id
      3                FROM   DUAL
      4              UNION ALL
      5              SELECT   83574 AS id, 135433 AS pe_rule_id, 46512 AS uc_id
      6                FROM   DUAL
      7              UNION ALL
      8              SELECT   83557 AS id, 137004 AS pe_rule_id, 47277 AS uc_id
      9                FROM   DUAL
     10              UNION ALL
     11              SELECT   83558 AS id, 139647 AS pe_rule_id, 47277 AS uc_id
     12                FROM   DUAL
     13              UNION ALL
     14              SELECT   83571 AS id, 144804 AS pe_rule_id, 46493 AS uc_id
     15                FROM   DUAL
     16              UNION ALL
     17              SELECT   83572 AS id, 144804 AS pe_rule_id, 46512 AS uc_id
     18                FROM   DUAL)
     19  select pe_rule_id, uc_id
     20  from taba where pe_rule_id in (
     21     SELECT   min(pe_rule_id)
     22     FROM   taba
     23     group by uc_id
     24*    having count(*) > 1)
    SQL> /
    
    PE_RULE_ID      UC_ID
    ---------- ----------
        137004      47277
        135433      46512
        135433      46493
    

    Published by: BluShadow on August 3, 2011 13:26
    p.s. Thanks for providing data in an easy to use format. :)

  • Why can't share tv recorded between 2 vista media center machines?

    TV registered on a machine can not be played on the other on a cable network even if the files can be shared, & have read/write permissions.

    Hi foxprints.

    Which edition of Windows Vista you are running on your system? Both the same?

    We must have the group policy in the editions of Vista that is present only in Vista Ultimate.

    But I can suggest a solution here and you can try to see if it works.

    NOTE: Important this section, method, or task contains steps that tell you how to modify the registry. However, serious problems can occur if you modify the registry incorrectly. Therefore, make sure that you proceed with caution. For added protection, back up the registry before you edit it. Then you can restore the registry if a problem occurs. For more information about how to back up and restore the registry, click on the number below to view the article in the Microsoft Knowledge Base:

    322756 how to back up and restore the registry in Windows: http://support.microsoft.com/kb/322756

    To change the strategy of group stuff use regedit and go to:

    \System\CurrentControlSet\Services\LanManSe rver\Parameters\NullSessionShares {HKEY_Local_Machine}

    If NullSessionShares there is not add that I did as a multiple string and Add TV recorded in this list.

    Also go to the {HKEY_Local_Machine} \System\CurrentControlSet\Control\Lsa\RestrictAnonymous
    and make sure that who is disabled.

    For more information, you can also refer to:

    http://thegreenbutton.com/forums/p/48133/393219.aspx

    For further assistance, you can also post your request here:

    http://thegreenbutton.com/forums/default.aspx

    Hope this information was useful.

    Let me know if it worked.

    Thank you, and in what concerns:

    UMA R - Engineer Support Microsoft Answers

    Visit our Microsoft answers feedback Forum and let us know what you think.

  • BlackBerry smartphone how to change view Contact to see category / group records only

    Hi everyone, just got my first BlackBerry.

    The Bold (9000) is the best screen.

    To be honest, I was anti-BlackBerry when they first came out.

    Did not like the feel of plastic.

    Now that the "BOLD" is here, and for some time, finally I turned.

    After using it for only a week, I must say, I am very impressed and now intend to continue to use it.

    I will also continue to have a second very basic phone.

    I thought that most of the things, even added many additional services, most of them style of Google.

    SE BIS, soon change BES to access our new SBS Exchange work.

    Even some of the most difficult functions, services and settings can be solved for me.

    I do not work in a dealership take Optus, mainly focused on business.

    On the issue...

    Is it possible to get your hands (first / default) connect with view to display the 'files' only category.

    I really wish I could open my contacts, select my category, then search.

    For me, it would be so much easier.

    For example. CONTACTS-Office-Steve

    or CONTACTS-family-MOM

    or CONTACTS-friends-David

    or CONTACTS-Optus-Wireless Technical Support

    This would save search me, especially since some contacts may have a different name, then I expect first (for example, 'hundreds' of Optus numbers, can be 'Pre-activation ULL' or 'Fixed installation support line')

    I guess he will have to show contacts that have not been assigned to a group (category).

    If these contacts have been enumerated below the category records, it would be ideal (for me).

    Perhaps, even if there was a possibility to classify them with the records of the category FIRST then all contacts in alpha?

    I know that a contact can be assigned to several categories (very useful).

    If this isn't an option, are there any recommended additional applications that can do this?

    I hope as clean and efficient as BlackBerry original aps.

    A few years ago, I used a Windows based mobile/PDA.

    To get more out of it, I also installed several aps SPB.

    Ultimately if an additional access point is required and is not free (IE must buy), it would really need a trial period.

    Thanks to anyone for ANY Advisor.

    I'm happy to be part of a more professional group.

    Ian

    This option as a view is not available on the BlackBerry, and I'm not aware of any third-party application to do, there could be.

    One option would be to name all your groups in such a way that they would appear first in your Contact list.

    As instead of naming a group of 'Friends', you would be the name "." See list Friends"with a period at the beginning, which will force this group name to the top of the Contact.

  • What is the preferred means of data transmission as a type of record between the nested table of pl/sql program or an associative array

    What is the preferred means of data transmission in the associative array of the nested table record vs

    Choose between Nested Tables and associative arrays

    The two nested tables and associative arrays (formerly index - by tables) use similar index notation, but they have different characteristics when it comes to persistence and ease of passing parameters.

    Nested tables can be stored in a column of data, but can of associative arrays. Nested tables can simplify the SQL operations where you would normally join a single-column table with a larger table.

    Associative arrays are appropriate for relatively small lookup tables where the collection can be constructed in memory whenever a procedure is called or a package is initialized. They are good for the collection of the information volume is unknown beforehand, because there is no fixed limit on their size. Their index values are more flexible, as associative array indices can be negative, can be no sequential and can use values of string instead of numbers.

    PL/SQL automatically converts between the bays of the host and the associative arrays that use values of digital keys. The most effective way to move the collections to and from the database server is to implement data values in associative arrays, and then use these associative arrays with erections in bulk (the FORALL statement or BULK COLLECT clause).

    With the help of documents and Collections of PL/SQL

    Read this:

    How to pass the record set as a parameter of the procedure.

    https://community.Oracle.com/thread/2375173?TSTART=0

  • Group records with time

    Hi all

    This is our requirement.

    We must combine records with time.

    for example: period = 3
    TABLE: XX_SALES
    ---------------------------------------------
    XDATE XQTY
    ---------------------------------------------
    10 5/1/2012
    20 2/5/2012
    3/5/2012 30
    4/5/2012 60
    12 2012/5/7
    8/5/2012 23
    45 8/5/2012
    100 12/5 / 2012
    5/2012/13 55
    5/2012/15 99

    == >
    ---------------------------------------------
    XDATE XQTY
    ---------------------------------------------
    1/5/2012 10-> 5/1/2012 Group (5/1/2012 ~ 3/5/2012)
    2/5/2012 20-> 5/1/2012 Group (5/1/2012 ~ 3/5/2012)
    3/5/2012 30-> 5/1/2012 Group (5/1/2012 ~ 3/5/2012)
    4/5/2012 60-> Group 5/2012/4 (4/5/2012 ~ 2012/5/6) *.
    7/5/2012 12-> Group 5/2012/7 (5/7/2012 ~ 9/5/2012) *.
    8/5/2012 23-> Group 5/2012/7 (5/7/2012 ~ 9/5/2012) *.
    8/5/2012 45-> Group 5/2012/7 (5/7/2012 ~ 9/5/2012) *.
    5/2012/12 100-> Group 5/12/2012 (2012/5/12 ~ 14/5/2012) *.
    13/5/2012 55-> Group 5/12/2012 (2012/5/12 ~ 14/5/2012) *.
    5/15/2012 99-> Group 5/15/2012 (15/5/2012 ~ 5/17/2012) *.

    After amount to combine with period = 3, the result will be
    ---------------------------------------------
    XDATE_G XQTY_G
    ---------------------------------------------
    60 1/5/2012
    4/5/2012 60
    2012/5/7 80
    12/5/2012 155
    5/2012/15 99


    Here's the example script
     
    create table XX_SALES(XDATE DATE, XQTY Number);
    insert into XX_SALES VALUES(to_date('20120501','YYYYMMDD'),10);
    insert into XX_SALES VALUES(to_date('20120502','YYYYMMDD'),20);
    insert into XX_SALES VALUES(to_date('20120503','YYYYMMDD'),30);
    insert into XX_SALES VALUES(to_date('20120504','YYYYMMDD'),60);
    insert into XX_SALES VALUES(to_date('20120507','YYYYMMDD'),12);
    insert into XX_SALES VALUES(to_date('20120508','YYYYMMDD'),23);
    insert into XX_SALES VALUES(to_date('20120508','YYYYMMDD'),45);
    insert into XX_SALES VALUES(to_date('20120512','YYYYMMDD'),100);
    insert into XX_SALES VALUES(to_date('20120513','YYYYMMDD'),55);
    insert into XX_SALES VALUES(to_date('20120515','YYYYMMDD'),99);
     
    We can solve this problem by using the loop now:
    to find the XDATE_G and it's rank in the loop and the XQTY in the range of the sum.
    DECLARE
      V_DATE_FROM DATE := NULL;
      V_DATE_TO   DATE := NULL;
      V_QTY_SUM   NUMBER := 0;
      CURSOR CUR_DATE IS
        SELECT DISTINCT XDATE FROM XX_SALES ORDER BY XDATE;
    BEGIN
      FOR REC IN CUR_DATE LOOP
        IF V_DATE_TO IS NULL OR REC.XDATE > V_DATE_TO THEN
          V_DATE_FROM := REC.XDATE;
          V_DATE_TO   := REC.XDATE + 3 - 1;
          SELECT SUM(XQTY)
            INTO V_QTY_SUM
            FROM XX_SALES
           WHERE XDATE >= V_DATE_FROM
             AND XDATE <= V_DATE_TO;
          DBMS_OUTPUT.PUT_LINE(TO_CHAR(V_DATE_FROM, 'YYYYMMDD') ||
                               '-----qty: ' || TO_CHAR(V_QTY_SUM));
        END IF;
      END LOOP;
    END;
    Is it possible to solve this problem by using analyze sql?


    Thanks in advance,
    Best regards
    Zhxiang

    Published by: zhxiangxie on April 26, 2012 14:41 fixed the grouping expected data

    There was an article about a similar problem in Oracle Magazine recently:

    http://www.Oracle.com/technetwork/issue-archive/2012/12-Mar/o22asktom-1518271.html

    See the section on the 'grouping beaches '. They needed a total cumulative who started once the total reaches a certain amount.

    You need a total cumulative which starts again when the date changes to group and the dates of beginning and end of each group must be determined dynamically.

    This can be done with the analytical functions.

    Here is a solution-based 'code listing 5', the solution MODEL, which is recommended in the article.

    SELECT FIRST_DATE, SUM(XQTY) SUM_XQTY FROM (
      SELECT * FROM xx_sales
      MODEL DIMENSION BY(ROW_NUMBER() OVER(ORDER BY XDATE) RN)
      MEASURES(XDATE, XDATE FIRST_DATE, XQTY)
      RULES(
        FIRST_DATE[RN > 1] =
          CASE WHEN XDATE[CV()] - FIRST_DATE[CV() - 1] >= 3
          THEN xdate[cv()]
          ELSE FIRST_DATE[CV() - 1]
          END
      )
    )
    GROUP BY first_date ORDER BY first_date;
    
    FIRST_DATE            SUM_XQTY
    --------------------- --------
    2012/05/01 00:00:00         60
    2012/05/04 00:00:00         60
    2012/05/07 00:00:00         80
    2012/05/12 00:00:00        155
    2012/05/15 00:00:00         99
    

    If you 9i, there is no function model. In this case, I can give you a solution using START WITH / CONNECT BY that does not work as well.

  • Output and group records into several column format problem

    Hi all

    I'm banging my head on the wall with this one. I have a query that displays the result in the form of two columns, it works fine.

    I have a problem when I try to use "group"for the field DSC1 doesn't show duplicates."  He transforms the output in column 2, column 3 and column 4 spots white all along.

    Someone knows how can I get it to display 2 columns of output and does not show in double DSC1 fields? The following are examples of what is happening:


    1 example of what he does without group (note to Apple is twice, which is not):

    Apples apples

    Orange peaches

    banannas grapes

    What I need to do (only show each DSC1 once and continue with the format of two columns) :

    oranges apples

    Fisheries banannas

    grapes

    Here is the code I use:

    < cfquery name = "getProduct" datasource = "mydb" >
    SELECT * from ecitm
    WHERE DSC1 <>' '
    order by DSC1

    < / cfquery >

    <! - start the 2-column output table - >

    < table border = "0" width = "90%" border = "0" align = "center" cellpadding = "5" cellspacing = "5" >

    < cfset newrow = false

    < b >
    < cfoutput query = "getProduct" group = "DSC1" >

    < cfif newrow EQ "true" >
    < b >
    < / cfif >
    < td >
    #DSC1 #.
    < cfif DSC2 NEQ "" > "".
    < br >
    #DSC2 #.
    < / cfif >

    < br >
    < a href = "DetailsList.cfm? ID = #getProduct.ID # & litm = #getProduct.LITM #" > VIEW < /a > DETAILS
    < table >

    < cfif getProduct.currentRow MOD 2 EQ 0 >
    < /tr >
    < cfset newrow = true >
    < cfelse >
    < cfset newrow = false >
    < / cfif >


    < / cfoutput >
    < /tr >
    < /table >

    The currentRow always property will count the number or records in the record setting loop, if you their output or not.

    Since you are not the output values for each record in the Recordset, you must count the itterations yourself.

    Put a meter of itteration before the loop.

    Update the counter at the top of the loop.

    OR on newer versions of CF

    Reset the counter in the true clause of the block, where you also define new line. >

    Then use the variable in the iit instead the currentRow property to determine the number of items have been posted.

    **** OR ****

    You could do a simple SQL command does not get duplicates first and then use a loop of simple without any of the grouping and additional logic that you do.

    
    
    SELECT DISTINCT *
         FROM ecitm
         WHERE DSC1 <> ' '
         ORDER BY DSC1
    
    
    
    
         #DSC1#
         
    
        
    
    
    

Maybe you are looking for

  • Manage computers on the Toshiba customer portal

    Hello I have a previously saved PC Toshiba which lay under the heading 'my computer' under my profile on the customer site of Toshiba, with my new laptop.When I tried to delete the old computer he deleted a new too!I am now unable to save the valid c

  • Problem running Subvi after construction of .exe

    Hi all I've seen much related to this topic but you have not found anything specific to my situation. I built a simple wrapper to launch different Subvi depending on whether it of Saturday or not. The vi works perfectly well as a vi in LV2012. But wh

  • BlackBerry 10 I can't get the copy function Chat works in text Messages

    I used the function of copy cat before copying complete history in text messages and paste it into a document of Docs To Go.  The conversation goes, the process seems to slow down, but it always worked.  Now I find that it works at all.  I use to sav

  • BlackBerry Smartphones Will I send after a security wipe?

  • Files zipped not opening

    I recently downloaded a folder zipped with music that is in wav format, after having extracted the folder I found when I open the file it takes forever to open the Explorer windows causing freeze. and when I try to delete the folder it freezes just s