Reg: Query group by problem

Hi,
I am trying to write query for report generation.According to my client requirment I need to calculate the difference
between two date columns for "n" number of rows and i need to find the number of rows which are smaller
than 2 and number of rows which are greater than 2 and calculate the percentage for number of rows which are smaller than 2.
It must grouped by a third column
I tried like this, but it shows that date column is not a grouped .....
But I dont want to group that date column... Plz adivce....
SELECT table1.column2,
      table2.column3,
      COUNT(*),
     CASE
             WHEN TO_NUMBER (table1.DTT_column3 - table1.DTT_column4) <=2
             THEN COUNT(*)
             ELSE NULL
        END
         AS sucess_count,
     CASE
             WHEN TO_NUMBER (table1.DTT_column3 - table1.DTT_column4) >2
             THEN COUNT(*)
             ELSE NULL
        END
        AS fail_count,
     FROM
     table1,
     table2
     WHERE table1.column1 =       table2.column2
     AND table1.column4 = value1
     GROUP BY table1.column2,table2.column3;TIA,
Message was edited by: ORCL
ORCLDB

May be something like this.
SQL> select * from v$version;
BANNER
Oracle Database 10g Enterprise Edition Release 10.2.0.2.0 - 64bi
PL/SQL Release 10.2.0.2.0 - Production
CORE    10.2.0.2.0      Production
TNS for HPUX: Version 10.2.0.2.0 - Production
NLSRTL Version 10.2.0.2.0 - Production
  1  with t
  2  as
  3  (select 1 id, to_date('01.02.2008','dd.mm.yyyy') date_1,
  4                to_date('03.02.2008','dd.mm.yyyy') date_2 from dual union all
  5   select 1,    to_date('03.02.2008','dd.mm.yyyy'),
  6                to_date('04.02.2008','dd.mm.yyyy') from dual union all
  7   select 2,    to_date('05.02.2008','dd.mm.yyyy'),
  8                to_date('06.02.2008','dd.mm.yyyy') from dual union all
  9   select 2,    to_date('01.02.2008','dd.mm.yyyy'),
10                to_date('05.02.2008','dd.mm.yyyy') from dual
11  )
12  select count(case when to_number(date_2 - date_1) <= 2 then 1 end) diff_2,
13        count(case when to_number(date_2 - date_1) > 2 then 1 end) diff_Greater_2,
14    1 - (  count(case when to_number(date_2 - date_1) > 2 then 1 end)
15         / count(case when to_number(date_2 - date_1) <= 2 then 1 end)
16        ) percent
17  from t
18  group by rollup(id)
19* having grouping_id(id) = 1
SQL> /
    DIFF_2 DIFF_GREATER_2    PERCENT
         3              1 .666666667It will be always useful if you could post your full oracle version and a sample test data.
Regards
Raj

Similar Messages

  • Query Group by problem

    Hi,
    Oracle - 10.2.0
    I am writing a query for a report generation. And my requirement is, i need to group a column in a query which selects many columns
    eg:
    SELECT no_id,v_no,v_name,v_addr FROM tb_name_a
    GROUP BY v_no
    any options plz advice...
    TIA,

    Hi ORCLDB, I guess your requirement can be full filled by following query
    SELECT no_id,v_no,v_name,v_addr FROM tb_name_a
    ORDER BY v_no
    i.e. : use ORDER BY instead of GROUP BY clause
    Message was edited by:
    imrahul

  • Linking Query group to an SAP role

    I am able to link the Query group to the role but when we test the user does not have access to it. I know this used to be a problems years ago that I thought was fixes. Any ideas on how to get this to work?

    Hi,
    Assign the required user groups to the user in Sq03. if user still getting same error even after assignments in Sq03, ask user to please change query areas as below and check.
    Sq01 --> Environment --> Query areas --> select "Stanard area (client-specific).
    Regards,
    Gowrinadh

  • Query in item problem

    Hellou everybody.
    I need your help. I am using forms 6i and i have a block with some non DB items. But items are synchronize with DB items for viewing results. I use this items for diplaying results from DB tables. In enter query mode i write condition in this text items and execute query.
    My problem is that i have text item which is VARCHAR2 type and I need to enter the condition for example > 1000. But i don't know how to convert this field to number. When i execute query under char type it not work properly (other result). I tried to change data type to number but i can't because it's not alowed to mixed types.
    select * from table_name where pag_cis > 100 - i need this
    select * from table_name where pag_cis > '100' - i have this
    Can you help me???

    You may use the set_block_property procedure built-in and the 'default_where' property so as to execute the query using the contents of your item (with the name of column , of course).
    Afterwards , you navigate to the db items block (with go_block('blockname')) and execute the query (built-in 'execute_query').
    Hope it helps
    Sim

  • Multi-query group above report creates more pages

    Hi,
    I have a multi-query group above report (paper only), the parent group creates 5 rows(subframes) all onto the same page, but then creates 4 more IDENTICAL pages!!?
    at the end I have 5 repating frames and 5 pages.
    If I set Maximum Records per Page to 1, I have 5 pages (IDENTICAL) with the first frame only...
    any idea?
    cheers
    Matteo

    hello,
    you will have to create a counter, that tells you the numbers of students (summary-column, function : count, reset on : course) and create a format-trigger on the heading that hides it when the number of students is 0.
    regards,
    the oracle reports team --pw                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Query Group in Query Category different with Authorization's group number

    Hi All,
    In Authorization screen, it allowed to authorize up to 20 query group
    Whereas in Query Category window, it has only max 15 query group.
    Anyone has idea on why is the difference?
    Thanks in advance,
    MH

    You have a very good point.  I believe something must be for system to use during development.  You may post a development request to see if the next version could have matched numbers of query groups.  The forum is on this link:
    /community [original link is broken]
    Thanks,
    Gordon
    Edited by: Paulo Calado on Jun 19, 2009 3:33 PM

  • Query Group and Authorization group is different

    Hi,
    In Authorization screen, it allowed to authorize up to 20 query group. Whereas in Query Category window, it has only max 15 query group. For future patch, is it possible to have matched query groups?
    Thanks.
    Regards,
    MH

    Hi,
    In Authorization screen, it allowed to authorize up to 20 query group. Whereas in Query Category window, it has only max 15 query group. For future patch, is it possible to have matched query groups?
    Thanks.
    Regards,
    MH

  • Configure custom query group in navigation menu

    How do we configure custom query groups? Say for example: I have created a custom query group and added my custom query definitions to it. How do I configure this so that when I click on Contract Management Tab on the workbench, my custom query group is invoked?
    I need to configure custom query group in navigation menu. Any help would be appreciated.
    Regards,
    Bindu Sharma

    Hi Bindu,
    As per my understanding, it is standard and query group cannot be added in the navigation but you can add your quries under Agreement and Claus Library.
    Kindly refer the blog for the same: http://scn.sap.com/docs/DOC-55733
    Let me know if you need any other information.
    Thanks,
    Kushagra A

  • Saved query groups authorization

    Dear All,
    Saved query groups - no.1 to no. 20 are available in the authorizations form.
    I see there are only 15 groups  in the query manager --> manage categories, and in the authorizations are 20. the remnants are 5. Where will the five groups to be used and be able to find ?
    I use SBO 2004A. I also see that it is happened in SBO 2005A. I have tried to find in SAP notes but I can't see.
    I appreciate your answers. TIA
    Rgds,

    Hi Steve,
    Seems that noone here on SDN knows the answer (including myself)
    I suggest that you raise that to SAP Support - to have them checking the case.
    Sorry,
    Frank

  • Easiest way to know the query group name?

    Hello All,
    This has been nagging at me for quite some time now. Would appreciate you inputs on the ways to find out the query group name for a set of queries we see on the UI.
    The obvious method is to search your query group from the list of query groups that system shows when we navigate to Setup->Queries and Reports->Query Groups. Do we have some other ways as well.
    Thanks In Advance
    Devesh

    Hi Devesh,
    If you know the query definition then the easiest way to find the query group would be to use "Search Query Groups by Queries Used" query on the Query Groups list page. This query allows you to select a query definition and returns the query group using the query.
    Or you could use "Query Group Review" query on the Query Groups list page. This returns all queries within all Query Groups. You can further refine your search by Query Name or Internal Name of the query you are interested in.
    If you want to do a general search for all buy-side list page or buy-side picker page query groups, search for <buylist> and <buypick> respectively.
    Hope this helps.
    Regards,
    Vikram

  • Group by problem at pivot table

    Hi,
    firstly i am making a table, everything is ok,
    after i click pivot table, st_desc column writes same value again, i couldnt understand the reason.
    please check my screen shots below,
    http://www.odilibrary.com/index.php/oracle-data-integrator/99-group-by-problem
    kindly advise please

    that my fault
    there is a null at the beginning of the value, they are different,
    sorry

  • GROUP BY PROBLEM IN QUERY

    HI ALL,
    MY TABLES ARE
    1. PRTRINCE FIEDS ARE: SHOP,TIMESAVED,TIMETAKEN,EMPNO
    2. PRMAINCM : UNIT, STDHOURS
    NOW I WANT TO DO THE FOLLOWING THING
    I WANT TO CALCULATE THE % FOR EACH SHOP AND SHOW ACCORDING TO SHOP
    I MEAN
    SELECT A.SHOP,SUM(A.TIMETAKEN),SUM(A.TIMESAVED)
    , SUM(A.TIMESAVED)*100/COUNT(A.EMPNO)*B.STDHOURS FROM
    PRTRINCE A, PRMAINCM B WHERE
    A.SHOP=B.UNIT
    GROUP BY A.SHOP
    BUT IT DOES NOT WORK AS IT SAYS COUNT(A.EMPNO)*B.STDHOURS NOT A GROUP BY EXPRESSION
    SUGGEST SOME QUERY THAT CAN SOLVE MY PROBLEM
    REGARDS
    ABHI.

    Hi Abhi,
    Include B.STDHOURS in your group by clause and check.
    SELECT A.SHOP,
           SUM(A.TIMETAKEN),
           SUM(A.TIMESAVED),
           SUM(A.TIMESAVED)*100/COUNT(A.EMPNO) * B.STDHOURS
    FROM PRTRINCE A, PRMAINCM B
    WHERE A.SHOP=B.UNIT
    GROUP BY A.SHOP, B.STDHOURS
    Tip: use proper brackets in your script as per your requirement:
    select 5 * 100 / 10 * 4 from dual
    =>200
    select 5 * 100 / (10 * 4) from dual
    =>12.5Slight modifications in the script: included disctinct for count(empno)
    with PRTRINCE as (
    select 'A' as SHOP, 10 as TIMESAVED, 50 as TIMETAKEN, 1 as EMPNO from dual union all
    select 'A' as SHOP, 15 as TIMESAVED, 45 as TIMETAKEN, 2 as EMPNO from dual union all
    select 'A' as SHOP, 5 as TIMESAVED, 60 as TIMETAKEN, 2 as EMPNO from dual union all
    select 'A' as SHOP, 15 as TIMESAVED, 45 as TIMETAKEN, 2 as EMPNO from dual union all
    select 'B' as SHOP, 12 as TIMESAVED, 48 as TIMETAKEN, 3 as EMPNO from dual
    PRMAINCM as
    select 'A' as UNIT, '8' as STDHOURS from dual union
    select 'B' as UNIT, '10' as STDHOURS from dual
    SELECT A.SHOP,
           SUM(A.TIMETAKEN) TIMETAKEN,
           SUM(A.TIMESAVED) TIMESAVED,
           (SUM(A.TIMESAVED)*100/COUNT(distinct A.EMPNO) * B.STDHOURS) XYZ
    FROM PRTRINCE A, PRMAINCM B
    WHERE A.SHOP=B.UNIT
    GROUP BY A.SHOP, B.STDHOURS
    SHOP     TIMETAKEN     TIMESAVED     XYZ
    A     200     45     18000
    B     48     12     12000Regards
    Imran
    Edited by: Imran Soudagar on Apr 13, 2010 10:35 AM; modified script with sample data

  • Reg: Query Problem for New Posting Period

    Hi Xperts,
    While I try to Map the A/P Invoices with their respective Outgoing Payment,
    I used the following Query and it's Query Printlayout
    SELECT T0.DocNum [Payment#], T0.DocDate [Payment Date],
    T0.CardCode, T0.CardName, T1.InvoiceId, T2.DocNum [AP Inv#],
    T2.NumatCard [Bill No.], T2.DocDate [Bill Date], T1.selfInv,
    T1.SumApplied, T1.WtAppld, T0.NoDocsum 
    FROM  [dbo].[OVPM] T0  INNER  JOIN
    [dbo].[VPM2] T1  ON  T1.[DocNum] = T0.DocNum
    INNER  JOIN [dbo].[OPCH] T2  ON  T2.[DocEntry] = T1.DocEntry
    WHERE T0.Cardname='[%0]' and T0.DocDate='[%1]' and
    T0.DocNum='[%2]'
    I got the above query from our Expert Mr.Sambath only.
    Now what is the problem is the query is retrieving the payment details of old Posting Period only and not the current posting period.
    In detail, I used 'Primary' Series for FY08-09, Period indicator 'Default'
    Now I'm using 'Primary1' Series for FY09-10, Period indicator '0910'
    Thanx in adv.
    Regards,
    Bala

    Hi Bala,
    Looking at your query, it is not query issue ,it is your data issue.
    Please check if you have data in  VPM2  table  which is bank transfer payment method
    Thank you
    Bishal
    Edited by: Bishal Adhikari on Apr 9, 2009 8:48 AM

  • CostCenter Group Aggregation problem. High Priority Issue.

    Hi Experts,
    I have very crital issue in the report, Help needed.
       I had some kind of requirement in one of the Overhead cost report, need to combine the COPA data and Costcenter(Over Head cost) data.  I have a problem with Costcenter Group aggregation on the report.
    I have Restricted 2-Keyfigures  want to derive the 3rd Keyfigure values. I given the below exmaple of the data. In my report I just want to display the KeyFigure(KF-A,B,C). I dont want to Display the Cost Center group/Costcenter Number in my report. My report ouput will be one line. But If I removed the costcenter Group I am seeing different values of the Keyfigure C, If I display the Costcenter comng with differnt Values. I am expecting the values in the column C is 1400 but it is coming like 3600.
    Please guide me how to design the Keyfigures if I want to get the value 1400 in theKeyFigre C with out Showing the Costcenter In the report.
    Cost-Center Group  R00048                         
                      Costcenter     KF-A     KF-B           KF-C
         10113     10     10          100
         10114     20     20          400
         10115     30     30          900
              60     60          1400(Insted of this its comming like 3600)
    Appreciate the response.
    Thanks,
    Venkata

    Hi,
    Check the display properties of key figure in Query Designer/Info object level.
    Set the property accordingly.
    I hope it will help.
    Thanks,
    S

  • Oracle Query Rewrite Alias Problem

    Hi,
    The problem desribed below is regarding the use of oracle aggregate awareness through the use of query rewrite.
    2 materialized views exist (one agg per day, one agg per month) and 1 dimension exists for time (date - month - quarter - year)
    Query rewrite seems to be working fine for a query as such (alias sql = alias mv):
    select DDFPC.MONTH_NO
    from BIDATA_MAIN.DF_REPOSITORY_SUBSET DF2, BIDATA_MAIN.DD_TIME DDFPC
    where DF2.FINANCIAL_PROCCESSING_DATE_ID = DDFPC.DATE_ID and DF2.ROUTING_CODE_ISS IN ('FPC','NCC')
    group by DDFPC.MONTH_NO
    However, considering our reporting tool generates aliases on the fly, we could get the following query (alias sql <> alias mv):
    select T2.MONTH_NO
    from BIDATA_MAIN.DF_REPOSITORY_SUBSET DF2, BIDATA_MAIN.DD_TIME T2
    where DF2.FINANCIAL_PROCCESSING_DATE_ID = T2.DATE_ID and DF2.ROUTING_CODE_ISS IN ('FPC','NCC')
    group by T2.MONTH_NO
    --> for the second query, query rewrite refuses to correctly use the dimension – it’ll rewrite to the DD (daily) aggregate, but not to the MM (monthly) aggregate
    Investigation gives: QSM-01072: materialized view, DA_REPOSITORY_MERCHANT_MM, and query have different joins between tables, DF_REPOSITORY_SUBSET and DD_TIME
    So*: How can query rewrite be forced to take place with different aliases between query & materialized view – taken into account a dimension is used for aggregation-awareness?
    This seems to indicate it should work...

    You are missing a join on the file_id column
    i.e.
    select sum(f.BLOCKS), sum(d.BLOCKS) from dba_free_space f ,dba_data_files d where f.TABLESPACE_NAME=d.TABLESPACE_NAME and f.TABLESPACE_NAME like SUBSTR('KU_TSD_1',0,10)
    and f.file_id = d.file_id
    This might have been easier to detect if you had removed the sum aggregation and looked at the data coming back from the raw query.

Maybe you are looking for

  • Converting .pages files

    I used Mac as my primary OS for years, and have accumulated a plethora of .pages files. I was wondering if anyone knew the simplest and easiest method for converting those to .txt or something else. I was hoping for something that can handle batches

  • Differemces between CRM 4.0 and CRM 5.0

    Hi Can someone help me out with 5-6 differences between CRMVersion 4 and 5? I need to know the differences from the Architecture side and in Sales and Marketing. Thanks Tarang

  • Adobe reader in E 71

    Recently I purchased E 71. Unfortunately the adobe reader is useless. It can only read very small file, other wise it says memory is not adequate and file can not be opened. Can any one help me.   Ullu

  • AE CS5 only see black when playing a rendered mov file in QT

    AE CS5 Mac 10.6:  After rendering a movie as Render:Best Settings / Output:Lossless I get an mov file (quite large, 193MB) - awesome thats what needs to happen.  Now upon viewing that mov file within QT, I get the timer (8 seconds) and the playhead s

  • Display and power issue with iBook G4

    My girlfriends iBook recently started acting up... here's the situation. I'm pretty sure it is a G4 but not positive. It's the "chiclet" version and a HD900? After coming back from a vacation the display seemed to go strange. I was able to get it to