Need a query for grouping

Hi,
I have some data and need to group it based on date. please see the below data
pkey--------from_date----------to_date------------amount-------------
1 ---------8-aug-12 ----------31-aug-12---------120
1 ---------31-aug-12 --------1-sep-12--------- 130
1 ---------1-sep-12 ----------2-sep-12--------- 150
1 ---------3-sep-12 ----------4-sep-12--------- 150
1 ---------5-sep-12 ----------7-sep-12--------- 100
1 ---------7-sep-12 ----------8-sep-12--------- 200
1 ---------8-sep-12 ----------20-sep-12---------120
1 ---------20-sep-12 --------1-oct-12--------- 130
1 ---------1-oct-12 ----------8-oct-12--------- 150
and so on.....
I need to group the data when a month finished.. e.g row 1 from_date is 08-aug-12 row 6 to_date is 08-sep-12 means almost 1 month finished so it should group and show the sum of amount with min(from_date) and max(to_Date) and total amount monhtly basis.
I am trying to make a query since many hours but no success.. the data is huge with many keys and dates ... please share your idea/tips/feedback.
Thanks
Edited by: hard_stone on Jan 18, 2013 11:38 AM

Try this
with t
as
select 1 pkey, to_date('08-aug-12', 'dd-mon-rr') from_date, to_date('31-aug-12', 'dd-mon-rr') to_date, 120 amount from dual
union all
select 2 pkey, to_date('31-aug-12', 'dd-mon-rr') from_date, to_date('01-sep-12', 'dd-mon-rr') to_date, 130 amount from dual
union all
select 3 pkey, to_date('01-sep-12', 'dd-mon-rr') from_date, to_date('02-sep-12', 'dd-mon-rr') to_date, 150 amount from dual
union all
select 4 pkey, to_date('03-sep-12', 'dd-mon-rr') from_date, to_date('04-sep-12', 'dd-mon-rr') to_date, 150 amount from dual
union all
select 5 pkey, to_date('05-sep-12', 'dd-mon-rr') from_date, to_date('07-sep-12', 'dd-mon-rr') to_date, 100 amount from dual
union all
select 6 pkey, to_date('07-sep-12', 'dd-mon-rr') from_date, to_date('08-sep-12', 'dd-mon-rr') to_date, 200 amount from dual
union all
select 7 pkey, to_date('08-sep-12', 'dd-mon-rr') from_date, to_date('20-sep-12', 'dd-mon-rr') to_date, 120 amount from dual
union all
select 8 pkey, to_date('20-sep-12', 'dd-mon-rr') from_date, to_date('01-oct-12', 'dd-mon-rr') to_date, 130 amount from dual
union all
select 9 pkey, to_date('01-oct-12', 'dd-mon-rr') from_date, to_date('08-oct-12', 'dd-mon-rr') to_date, 150 amount from dual
select min(from_date) from_date, max(to_date) to_date, sum(amount) amount
  from (
        select pkey, from_date, to_date, amount, next_month
          from t
         model
         dimension by (pkey)
         measures (from_date, to_date, amount, to_date('19000101', 'yyyymmdd') next_month, add_months(from_date, 1) temp_month)
         rules upsert
           next_month[any] = case when next_month[cv(pkey)-1] >= to_date[cv(pkey)] then next_month[cv(pkey)-1]
                                  else temp_month[cv(pkey)] end
group by next_month;
FROM_DATE TO_DATE   AMOUNT
08-AUG-12 08-SEP-12    850
08-SEP-12 08-OCT-12    400

Similar Messages

  • Need a query for monthly Report

    Hello All,
    I need a query for monthly report,
    comp_code
    emp_id
    dept_id
    work_day
    100
    A100
    MECH
    01/01/2013
    100
    A100
    MECH
    02/01/2013
    100
    A100
    MECH
    03/01/2013
    100
    A100
    MECH
    04/01/2013
    100
    A100
    MECH
    05/02/2013
    100
    A100
    MECH
    08/02/2013
    100
    A100
    MECH
    09/02/2013
    100
    A100
    MECH
    10/02/2013
    100
    A100
    MECH
    12/05/2013
    100
    A100
    MECH
    13/05/2013
    100
    A101
    CIV
    01/04/2013
    100
    A101
    CIV
    02/04/2013
    100
    A101
    CIV
    03/04/2013
    100
    A101
    CIV
    04/04/2013
    100
    A101
    CIV
    06/04/2013
    100
    A101
    CIV
    06/06/2013
    100
    A101
    CIV
    07/06/2013
    100
    A101
    CIV
    08/06/2013
    100
    A101
    CIV
    09/06/2013
    100
    A101
    CIV
    10/06/2013
    100
    A101
    CIV
    11/12/2013
    100
    A101
    CIV
    12/12/2013
    100
    A101
    CIV
    13/12/2013
    100
    A101
    CIV
    14/12/2013
        Dear friends this the sample table of my report.In which table has contain list of  employees with their working days(actual table has contain almost 5laks of records).
    suppose user choose the date between 01/01/2013 and 31/12/2013 then the result should be like this.
    comp_code
    emp_id
    dept_id
    month
    Total_work
    100
    A100
    MECH
    JANUARY
    4
    100
    A100
    MECH
    FEBRUARY
    2
    100
    A100
    MECH
    MARCH
    0
    100
    A100
    MECH
    APRIL
    0
    100
    A100
    MECH
    MAY
    2
    100
    A100
    MECH
    JUNE
    0
    100
    A100
    MECH
    JULY
    0
    100
    A100
    MECH
    AUGUST
    0
    100
    A100
    MECH
    SEPTEMBER
    0
    100
    A100
    MECH
    OCTOBER
    0
    100
    A100
    MECH
    NOVEMBER
    0
    100
    A100
    MECH
    DECEMBER
    0
    100
    A101
    CIV
    JANUARY
    0
    100
    A101
    CIV
    FEBRUARY
    0
    100
    A101
    CIV
    MARCH
    0
    100
    A101
    CIV
    APRIL
    5
    100
    A101
    CIV
    MAY
    0
    100
    A101
    CIV
    JUNE
    5
    100
    A101
    CIV
    JULY
    0
    100
    A101
    CIV
    AUGUST
    0
    100
    A101
    CIV
    SEPTEMBER
    0
    100
    A101
    CIV
    OCTOBER
    0
    100
    A101
    CIV
    NOVEMBER
    0
    100
    A101
    CIV
    DECEMBER
    4

    Hi,
    If you want the output to include months where no work was done (with 0 in the total_work column) then you need to outer-join a "table" that has one row per month, and make it a partitioned outer join:
    WITH  got_end_points   AS
       SELECT  TRUNC (MIN (work_day), 'MONTH')   AS first_month
       ,       TRUNC (MAX (work_day), 'MONTH')   AS last_month
       FROM    table_x
    ,   all_months   AS
       SELECT  ADD_MONTHS (first_month, LEVEL - 1)   AS a_month
       ,       ADD_MONTHS (first_month, LEVEL)       AS next_month
       FROM    got_end_points
       CONNECT BY  LEVEL <= 1 + MONTHS_BETWEEN (last_month, first_month)
    SELECT    t.comp_code
    ,         t.emp_id
    ,         t.dept_id
    ,         m.a_month
    ,         COUNT (t.work_day) AS total_work
    FROM             all_months  m
    LEFT OUTER JOIN  table_x     t  PARTITION BY (t.comp_code, t.emp_id, t.ept_id)
                                    ON   t.work_day  >= a.a_month
                                    AND  t.work_day  <  a.next_month
    GROUP BY  t.comp_code
    ,         t.emp_id
    ,         t.dept_id
    ,         m.a_month
    ORDER BY  t.comp_code
    ,         t.emp_id
    ,         t.dept_id
    ,         m.a_month
    As posted, this include every month that is actually in the table.  You can change the first sub-query if you want to enter first and last months.
    I hope this answers your question.
    If not, post  a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all tables involved, and also post the results you want from that data.
    Point out where the query above is giving the wrong results, and explain, using specific examples, how you get the correct results from the given data in those places.  If you changed the query at all, post your code.
    Always say which version of Oracle you're using (e.g., 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • Need a query for export table data .....

    Hi,
    I need a query for exporting the data in a table to a file.
    Can anyone help me ?
    Thanking You
    Jeneesh

    SQL> spool dept.txt
    SQL> select * from dept;
        DEPTNO DNAME          LOC
            10 ACCOUNTING     NEW YORK
            20 RESEARCH       DALLAS
            30 SALES          CHICAGO
            40 OPERATIONS     BOSTON
    SQL> spool off
    SQL> ed dept.txt

  • Need a Query for getting ItemCost from PO Vendor wise

    Hi,Experts We are not maintain different price list for  some particular items , We raised the PO for Multiple vendors with differnt price for the same material. We need a query to find the Item cost with Various Vendor .
    I need the query in the following format
    Po Number, Vendor Name,Item Name, Item Description,Qty, Price,Tax.
    Thanks
    Kamal

    Hi,
    Check this query which looks for the Item doctype Purchase Order and brings the data accordingly :
    select t0.docnum as 'PO Number', t0.CardName as 'Vendor name', t1.itemcode as 'Item Name',
    t1.Dscription as 'Item Description', t1.quantity as 'QTY', t1.Price as 'Price',
    t1.vatsum as 'Tax Amount'
    from OPOR t0 inner join POR1 t1 on t0.docentry = t1.docentry
    where t0.doctype ='I'
    Group by t1.itemcode, t1.Dscription, t0.docnum,
    t0.cardname, t1.quantity, t1.Price, t1.vatsum
    Order by t1.Itemcode
    Check if it helps.
    Kind Regards,
    Jitin
    SAP Business One Forum Team

  • Need a query for access tables

    Hi
    I need a query , help please:
    table1:
    id              description                  serial                    
    1                des1                           ser1
    2                des2                           ser2
    3                des3                           ser3
    table2:
    id            id1(id of table1)                date                
    stat
    1              1                                      
    2001                 A
    2              1                                      
    2008                 N
    3              2                                      
    2010                 A
    4              1                                      
    2012                 F
    ==============
    i need this data structure: (stat column must return for maximum date of id1 from table2)
    id(from table1)            serial(from table1)                  stat(from table2)
    1                                    ser1                
                           2012
    2                                    ser2             
                              2010
    3                                    ser3             
                               Null

    maybe you can try this.
    declare @t1 table
    (id int,[description] varchar(50),serial varchar(10))
    declare @t2 table
    (id int,id1 int,[date] char(4),stat char(10))
    insert into @t1 values
    (1,'des1','ser1'),
    (2,'des2','ser2'),
    (3,'des3','ser3')
    insert into @t2 values
    (1,1,'2001','A'),
    (2,1,'2008','N'),
    (3,2,'2010','A'),
    (4,1,'2012','F')
    select a.id,a.serial,max(b.date)
    from @t1 a
    left join @t2 b
    on a.id = b.id1
    group by a.id,a.serial
    | SQL PASS Taiwan Page |
    SQL PASS Taiwan Group
    |
    My Blog

  • Query for Group by & order by

    Hi all,
    I have a table name as angdata77 having attributes like asigno..
    i want to retrieve data from angdata77 by using both group by & order by clauses.. for total count..
    am using the query as
    select asigno,count(*) from angdata77 group by asigno order by asigno;
    Is there any other query for retrieving the data from angdata77
    Thanks in Advance,
    Venkatesh J.

    885756 wrote:
    Ya it's good.. Performance also good while retrieving data...
    I want to know other Possibilities also sir...There will be no better alternative for this, because this is the most simple and straight forward way to get the output you are looking for..
    Go ahead without any confusion... :)

  • Need sql query for typical scenario

    Hello Champs,
    I have a scenario where I am suppose to fetch data from a schema which is developed by other team ... (there are no primary keys even)
    the table structure is -
    Column A Column B Column C Column D
    1 h 6 u
    1 h 7 u
    1 h 8 u
    2 g 9 i
    2 g 0 i
    2 g 7 i
    3 t 3 h
    3 t 4 h
    3 t 5 i
    and my output should be exactly like :
    1 h 6,7,8 u
    2 g 9,0,7 i
    3 t 3,4 h
    so basically I want comma separated values for column c where remaining column values are same ...
    is it possible to achieve this result via SQL?? if not then what is the other solution??
    Please help .. I am working in IST and need solution urgently for this .. please help .
    TIA,
    Regards,
    Chintan

    if you have 11g
    WITH t AS (SELECT 1 cola,
                      'h' colb,
                      6 colc,
                      'u' cold
                 FROM DUAL
               UNION
               SELECT 1,
                      'h',
                      7,
                      'u'
                 FROM DUAL
               UNION
               SELECT 1,
                      'h',
                      8,
                      'u'
                 FROM DUAL
               UNION
               SELECT 2,
                      'g',
                      9,
                      'i'
                 FROM DUAL
               UNION
               SELECT 2,
                      'g',
                      0,
                      'i'
                 FROM DUAL
               UNION
               SELECT 2,
                      'g',
                      7,
                      'i'
                 FROM DUAL
               UNION
               SELECT 3,
                      't',
                      3,
                      'h'
                 FROM DUAL
               UNION
               SELECT 3,
                      't',
                      4,
                      'h'
                 FROM DUAL
               UNION
               SELECT 3,
                      't',
                      5,
                      'i'
                 FROM DUAL)
      SELECT cola, colb,  listagg (colc, ',') WITHIN GROUP (ORDER BY colc) colc, cold
        FROM t
    GROUP BY cola, colb, cold
    COLA     COLB     COLC     COLD
    1     h     6,7,8     u
    2     g     0,7,9     i
    3     t     3,4     h
    3     t     5     i

  • Help needed in query for Materialized View

    Hi,
    I want to create a materialized view which has some precalcultaed values.
    I have four dimension tables out of which one is a Time Dimension table with levels as Year->Quarter->Month.
    The precalculations are the moving averages and cummulative values of Sales Amt on the dimension values over a period of 4 Months.
    The dimension tables are Clients, Products, Channel, Time.
    Fact Table is Sales_Fact which will have the sales amount for different members of the dimension.
    Since my fact table is very huge, i want to create a materialized view where i could store the required calculated measures, here Moving Average of Sales Amt for each Client, Product, Channel dimensions over a period of 4 Months.
    Can anybody help with writing the query for this..Any help in this regard will be appreciated..
    Please give me suggestions for this..

    Check this link.
    http://download.oracle.com/docs/cd/B19306_01/server.102/b14223/aggreg.htm#sthref1612
    Regards
    Raj

  • How to write a query for grouping them the columns and give the sequence order to each group/

    Hi i have table that contains country columns .
    India,USA,UK like these when ever the group changed into the differt country i make a group and arrange them the sequence into those Countries
    like below
    1)India
    2)India
    1)USA
    2)USA
    like these to write a query ..........pls help me for this query

    Assuming you're using SQL Server you can ask here:
    http://www.sqlteam.com/forums/forum.asp?FORUM_ID=23
    Otherwise, please ask in the relevant forum for the type of technology you're using.
    Basically it's either:
    select *
    from [table name]
    order by country
    If you want to do something with groups do something like:
    select (max) income, country
    from [table name]
    group by country
    Kind regards,
    Margriet Bruggeman
    Lois & Clark IT Services
    web site: http://www.loisandclark.eu
    blog: http://www.sharepointdragons.com

  • Need sql query for all employees list which are having lessthan maximum salary of manager in same departmnet;

    HI
    I want a sql query i.e., all employees list which are having lessthan maximum salary of manager in same departmnet;
    my table is like this
    employees
    EMPLOYEE_ID                               NOT NULL NUMBER(6)
    FIRST_NAME                                                   VARCHAR2(20)
    LAST_NAME                                 NOT NULL    VARCHAR2(25)
    EMAIL                                     NOT NULL          VARCHAR2(25)
    PHONE_NUMBER                                              VARCHAR2(20)
    HIRE_DATE                                 NOT NULL        DATE
    JOB_ID                                    NOT NULL           VARCHAR2(10)
    SALARY                                                           NUMBER(8,2)
    COMMISSION_PCT                                          NUMBER(2,2)
    MANAGER_ID                                                  NUMBER(6)
    DEPARTMENT_ID                                             NUMBER(4)
    if need the department table
    departments:
    DEPARTMENT_ID                        
    NOT NULL NUMBER(4)
    DEPARTMENT_NAME                      
    NOT NULL VARCHAR2(30)
    MANAGER_ID                                    
    NUMBER(6)
    LOCATION_ID                                   
    NUMBER(4)

    Try this:
    select
       employees.last_name || ', ' || employees.first_name “Employee”,
       employees.salary “Emp Salary”,
       sub.salary “Mgr Salary”,
       employees.department_id  “Department” 
    from
       employees,
       (  select
          mgr.department_id dept,
          max(mgr.salary) salary     
       from
          employees,
          employees mgr      
       where
          employees.mgr = mgr.employee_id      
       group by
          mgr.department_id) sub   
    where
       employees.department_id = sub.dept      
       and employees.salary < sub.salary
    Jeff

  • SQL - Need Tunning tips for group by [LATEST EXECUTION PLAN IS ATTACHED]

    Hi All Experts,
    My SQL is taking so much time to execute. If I remove the group by clause it is running within a minute but as soon as I am putting sum() and group by clause it is taking ages to run the sql. Number of records are wihout group by clause is almost 85 Lachs (8 Million). Is hugh dataset is killing this? Is there any way to tune the data on Group by clause. Below is my Select hints and execution plan. Please help.
    SQL
    SELECT /*+ CURSOR_SHARING_EXACT gather_plan_statistics all_rows no_index(atm) no_expand
    leading (src cpty atm)
    index(bk WBKS_PK) index(src WSRC_UK1) index(acct WACC_UK1)
    use_nl(acct src ccy prd cpty grate sb) */
    EXECUTION PLAN
    PLAN_TABLE_OUTPUT
    SQL_ID 1y5pdhnb9tks5, child number 0
    SELECT /*+ CURSOR_SHARING_EXACT gather_plan_statistics all_rows no_index(atm) no_expand leading (src cpty atm) index(bk
    WBKS_PK) index(src WSRC_UK1) index(acct WACC_UK1) use_nl(acct src ccy prd cpty grate sb) */ atm.business_date,
    atm.entity legal_entity, TO_NUMBER (atm.set_of_books) setofbooksid, atm.source_system_id sourcesystemid,
    ccy.ccy_currency_code ccy_currency_code, acct.acct_account_code, 0 gl_bal, SUM (atm.amount)
    atm_bal, 0 gbp_equ, ROUND (SUM (atm.amount * grate.rate), 4) AS
    atm_equ, prd.prd_product_code, glacct.parentreportingclassification parentreportingclassification,
    cpty_counterparty_code FROM wh_sources_d src,
    Plan hash value: 4193892926
    | Id | Operation | Name | Starts | E-Rows | A-Rows | A-Time | Buffers | Reads | OMem | 1Mem | Used-Mem |
    | 1 | HASH GROUP BY | | 1 | 1 | 471 |00:31:38.26 | 904M| 76703 | 649K| 649K| 1149K (0)|
    | 2 | NESTED LOOPS | | 1 | 1 | 8362K|00:47:06.06 | 904M| 76703 | | | |
    | 3 | NESTED LOOPS | | 1 | 1 | 10M|00:28:48.84 | 870M| 17085 | | | |
    | 4 | NESTED LOOPS | | 1 | 1 | 10M|00:27:56.05 | 849M| 17084 | | | |
    | 5 | NESTED LOOPS | | 1 | 8 | 18M|00:14:10.93 | 246M| 17084 | | | |
    | 6 | NESTED LOOPS | | 1 | 22 | 18M|00:11:58.96 | 189M| 17084 | | | |
    | 7 | NESTED LOOPS | | 1 | 22 | 18M|00:10:24.69 | 152M| 17084 | | | |
    | 8 | NESTED LOOPS | | 1 | 1337 | 18M|00:06:00.74 | 95M| 17083 | | | |
    | 9 | NESTED LOOPS | | 1 | 1337 | 18M|00:02:52.20 | 38M| 17073 | | | |
    |* 10 | HASH JOIN | | 1 | 185K| 18M|00:03:46.38 | 1177K| 17073 | 939K| 939K| 575K (0)|
    | 11 | NESTED LOOPS | | 1 | 3 | 3 |00:00:00.01 | 11 | 0 | | | |
    | 12 | TABLE ACCESS BY INDEX ROWID | WH_SOURCES_D | 1 | 3 | 3 |00:00:00.01 | 3 | 0 | | | |
    |* 13 | INDEX RANGE SCAN | WSRC_UK1 | 1 | 3 | 3 |00:00:00.01 | 2 | 0 | | | |
    |* 14 | TABLE ACCESS BY INDEX ROWID | WH_COUNTERPARTIES_D | 3 | 1 | 3 |00:00:00.01 | 8 | 0 | | | |
    |* 15 | INDEX UNIQUE SCAN | WCPY_U1 | 3 | 1 | 3 |00:00:00.01 | 5 | 0 | | | |
    | 16 | PARTITION RANGE SINGLE | | 1 | 91M| 91M|00:00:00.08 | 1177K| 17073 | | | |
    |* 17 | TABLE ACCESS FULL | WH_ATM_BALANCES_F | 1 | 91M| 91M|00:00:00.04 | 1177K| 17073 | | | |
    |* 18 | TABLE ACCESS BY INDEX ROWID | WH_PRODUCTS_D | 18M| 1 | 18M|00:01:43.88 | 37M| 0 | | | |
    |* 19 | INDEX UNIQUE SCAN | WPRD_UK1 | 18M| 1 | 18M|00:00:52.13 | 18M| 0 | | | |
    |* 20 | TABLE ACCESS BY GLOBAL INDEX ROWID| WH_BOOKS_D | 18M| 1 | 18M|00:02:53.01 | 56M| 10 | | | |
    |* 21 | INDEX UNIQUE SCAN | WBKS_PK | 18M| 1 | 18M|00:01:08.32 | 37M| 10 | | | |
    |* 22 | TABLE ACCESS BY INDEX ROWID | T_SDM_SOURCEBOOK | 18M| 1 | 18M|00:03:43.66 | 56M| 1 | | | |
    |* 23 | INDEX RANGE SCAN | TSSB_N5 | 18M| 2 | 23M|00:01:11.50 | 18M| 1 | | | |
    |* 24 | TABLE ACCESS BY INDEX ROWID | WH_CURRENCIES_D | 18M| 1 | 18M|00:01:51.21 | 37M| 0 | | | |
    |* 25 | INDEX UNIQUE SCAN | WCUR_PK | 18M| 1 | 18M|00:00:49.26 | 18M| 0 | | | |
    | 26 | TABLE ACCESS BY INDEX ROWID | WH_GL_DAILY_RATES_F | 18M| 1 | 18M|00:01:55.84 | 56M| 0 | | | |
    |* 27 | INDEX UNIQUE SCAN | WGDR_U2 | 18M| 1 | 18M|00:01:10.89 | 37M| 0 | | | |
    | 28 | INLIST ITERATOR | | 18M| | 10M|00:22:40.03 | 603M| 0 | | | |
    |* 29 | TABLE ACCESS BY INDEX ROWID | WH_ACCOUNTS_D | 150M| 1 | 10M|00:20:19.05 | 603M| 0 | | | |
    |* 30 | INDEX UNIQUE SCAN | WACC_UK1 | 150M| 5 | 150M|00:10:16.81 | 452M| 0 | | | |
    | 31 | TABLE ACCESS BY INDEX ROWID | T_SDM_GLACCOUNT | 10M| 1 | 10M|00:00:50.64 | 21M| 1 | | | |
    |* 32 | INDEX UNIQUE SCAN | TSG_PK | 10M| 1 | 10M|00:00:26.17 | 10M| 0 | | | |
    |* 33 | TABLE ACCESS BY INDEX ROWID | WH_COMMON_TRADES_D | 10M| 1 | 8362K|00:18:52.56 | 33M| 59618 | | | |
    |* 34 | INDEX UNIQUE SCAN | WCTD_PK | 10M| 1 | 10M|00:03:06.56 | 21M| 5391 | | | |
    Edited by: user535789 on Mar 17, 2011 9:45 PM
    Edited by: user535789 on Mar 20, 2011 8:33 PM

    user535789 wrote:
    Hi All Experts,
    My SQL is taking so much time to execute. If I remove the group by clause it is running within a minute but as soon as I am putting sum() and group by clause it is taking ages to run the sql. Number of records are wihout group by clause is almost 85 Lachs (*8 Million*). Is hugh dataset is killing this? Is there any way to tune the data on Group by clause. Below is my Select hints and execution plan. Please help.I doubt that your 8 million records are shown within minutes.
    I guess that the output started after a few minutes. But this does not mean that the full resultset is there. It just means the database is able to return to you the first few records after a few minutes.
    Once you add a group by (or an order by) then this requires that all the rows need to be fetched before the database can start showing them to you.
    But maybe you could run some tests to compare the full output. I find it useful to SET AUTOTRACE TRACEONLY for such a purpose (in sql plus). This avoids to print the selection on the screen.

  • Need a query for duplicate records deletion

    here is one scenario...
    23130 ----> 'A'
    23130 ----> 'X'
    23130 ----> 'c'
    These are duplicate records.. when we remove duplicates, the record must get 'c', if it contains A,C,X. If it contains A and X, then the record must get 'X'. That means the priority goes like this C-->X-->A. for this i need query.. this is one scenario. It would be great if u reply me asap.

    Hello
    It's great that you gave examples of your data, but it is quite helpful to supply create table and insert statements too along with a clear example of expected results. Anyway, I think this does what you are looking for.
    CREATE TABLE dt_dup (ID NUMBER, flag VARCHAR2(1))
    INSERT INTO dt_dup VALUES(23130, 'A');
    insert into dt_dup values(23130, 'X');
    insert into dt_dup values(23130, 'C');
    INSERT INTO dt_dup VALUES(23131, 'A');
    INSERT INTO dt_dup VALUES(23131, 'X');
    DELETE
    FROM
      dt_dup
    WHERE
      ROWID IN (  SELECT
                    rid
                  FROM
                    (   SELECT
                          rowid rid,
                          ROW_NUMBER() OVER (PARTITION BY ID ORDER BY CASE
                                                                        WHEN flag = 'A' THEN
                                                                          3
                                                                        WHEN flag = 'X' THEN
                                                                          2
                                                                        WHEN flag = 'C' THEN
                                                                          1
                                                                      END
                                            ) rn
                        FROM
                          dt_dup
                  WHERE
                    rn > 1
    select * from dt_dup;HTH
    David
    Edited by: Bravid on Jun 30, 2011 8:12 AM

  • Need a Query for the following Output

    I have a table name Table1. some of the data are like the following
    EmpCode    ProductCode    Quantity
    20006         IMPLSA                  5
    20006         LACJDT                 10
    20006         LIVLSU                 15
    20006         PEPPSU                 11
    20006         SAFMTA                 12
    20006         SUCFTA                 17
    21475         IMPLSA                  2
    21475         LACJDT                  7
    21475         LIVLSU                  4
    21475         PEPPSU                  8
    21475         SUCFTA                 12
    20409         IMPLSA                 11
    20409         LACJDT                 13
    20409         LIVLSU                  9
    20409         SAFMTA                  7
    20409         SUCFTA                  5
    21112         IMPLSA                  2
    21112         LIVLSU                 18
    21112         PEPPSU                 20
    21112         SAFMTA                 22
    21112         SUCFTA                 15
    Here no of EmpCode and ProductCode are not fixed.
    And i need the output like this
    ProductCode    20006    21475    20409    21112
    IMPLSA                   5           2           11       
    2
    LACJDT                 10           7           13        0
    LIVLSU                 15           4             9      18
    PEPPSU                11          8              0      20
    SAFMTA                12          0              7      22
    SUCFTA                17        12              5      15
    I know that it may be solved by dynamic pivot. but i never write any dynamic pivot query.
    So Please Help me.

    DECLARE @EmpList varchar(max),@SQL varchar(max)
    SELECT @EmpList = STUFF((SELECT DISTINCT ',[' + CAST(EmpCode AS varchar(15)) + ']'
    FROM Table1
    ORDER BY ',[' + CAST(EmpCode AS varchar(15)) + ']'
    FOR XML PATH('')),1,1,'')
    SET @SQL='SELECT ProductCode,' + @EmpList +
    ' FROM table1 t
    PIVOT(SUM(Quantity) FOR EmpCode IN (' + @EmpList + '))p'
    EXEC (@SQL)
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • Need SQl Query for Revenue Code and Revenue Amount in Receivables

    Hi,
    I need a SQL Query to develop data set for the following columns:
    Revenue Code,Revenue Code Description,Invoice Amount,Revenue Amount,Original Invoice Number,Original Invoice Date.
    Can i get from ra_cust_trx_line_gl_dist_all and ra_customer_trx_all and ra_customer_trx_lines_all by joining them.But for the columns whcih to take
    i am in dilemma.
    Kindly any help will be needful for me

    Hi,
    I need a SQL Query to develop data set for the following columns:
    Revenue Code,Revenue Code Description,Invoice Amount,Revenue Amount,Original Invoice Number,Original Invoice Date.
    Can i get from ra_cust_trx_line_gl_dist_all and ra_customer_trx_all and ra_customer_trx_lines_all by joining them.But for the columns whcih to take
    i am in dilemma.
    Kindly any help will be needful for me

  • Querying for group/distribution list

    Hello,
    Currently we are trying to query the distribution or groups list from the GWWS, but the only thing we get is a huge list of users, which are from all groups.
    We are using this filter:
    Code:
    <getItemsRequest>
    <container>GroupWiseSystemAddressBook@52</container>
    <view>default members</view>
    <filter>
    <elements>
    <op>and</op>
    <element>
    <op>eq</op>
    <field>@type</field>
    <value>Group</value>
    </element>
    <element>
    <op>eq</op>
    <field>name</field>
    <value>Developers</value>
    </element>
    </elements>
    </filter>
    </getItemsRequest>
    Is there someone who can provide us with the right filter ?
    Thanks in advance,
    Eamon Woortman
    Developer at Maintainet AG

    Thanks for your response.
    We got it working using this filter:
    Code:
    <getItemsRequest>
    <container>GroupWiseSystemAddressBook@52</container>
    <view>default members</view>
    <filter>
    <elements>
    <op>and</op>
    <element type="FilterEntry">
    <op>eq</op>
    <field>@type</field>
    <value>Group</value>
    </element>
    <element type="FilterEntry">
    <op>eq</op>
    <field>username</field>
    <value>Developers</value>
    </element>
    </elements>
    </filter>
    </getItemsRequest>

Maybe you are looking for

  • How to see all items in use

    This should be a pretty simple problem, but I can't seem to figure out how to solve it. I'm trying to empty two items out of the trash, but when I attempt to is says "the operation cannot be completed because the "each item" is in use." However, I cl

  • Why am I unable to use anything when I open Firefox?

    I've been having this problem since I installed the beta. When I open up Firefox, the screen immediately freezes. Nothing is able to function: the url bar, my home page, the menu bar, NOTHING. I've even tried reinstalling the beta twice (beta 4.9 and

  • Adobe Reader Extension Software 7

    From where can I get / download the Adobe Reader Extension Server 7.0 I tried on "http://www.adobe.com/products/server/readerextensions/main.html" link also, but there it does not give any link for download. Regards Tejraj

  • JMS Connection Issue

    Dear all, i have a message listener that overrides onMessage and performs some business logic. i call business method from onMessage method. My query is "Does the queue connection factory session and connection remain open till the time the business

  • Headset iPad 3 Skype

       Hello I have a DR-BT21G Sony headset when Inplay music on skype works perfect but when I use skype sometimes the audio go to iPad speakrs instead the headset and about the voice msgs in Skype simply all play on iPad speakers instead the headset no