Query to display multiple counts in the result

Hi,
I need to be able to display multiple counts for different items in the single result set:
Here is the simplified schema:
I have 2 tables:
STATEMENT table:
===============
statement_pk number,
department varchar2(20)
STATEMENT_INFO table:
===================
statement_info_pk number,
statement_fk number
is_statement_done varchar2(1)
is_statement_locked varchar2(1)
I need to display counts of how many records where done and how records where locked in the
single output:
Statement_PK Department NumberOfStatementsDone# NumberofStatementsLocked#
1          ABC_dept          3                    5
2          DEF_dept          4                    8
3          XYZ_dept          7                    2
The following does not work:
SELECT
s.statement_pk,
s.department,
COUNT(r.statement_info_pk ) NumberOfStatementsDone# ,
COUNT(rr.statement_info_pk ) NumberOfStatementsLocked#
FROM STATEMENT s ,
STATEMENT_INFO r,
STATEMENT_INFO rr
WHERE
     s.statement_pk = r.statement_fk
     AND     s.statement_pk = rr.statement_fk
     AND      is_statement_done = 'Y'      AND rr.is_statement_locked = 'Y'
GROUP BY statement_pk, s.department
I was trying to work with analytic function but could not figured it out either.
Please help
Thanks,
Ia.

this would be something like:
SQL> r
  1  select statement_pk,
  2         department,
  3         sum(decode(is_statement_done, 'Y', 1, 0)) statement_done,
  4         sum(decode(is_statement_locked, 'Y', 1, 0)) statement_locked
  5  from   statement_info,
  6         statement
  7  where  statement_fk = statement_pk
  8* group by statement_pk, department
STATEMENT_PK DEPARTMENT           STATEMENT_DONE STATEMENT_LOCKED
           1 ABC_dept                          4                1
           2 DEF_dept                          6                2
           3 XYZ_dept                          1                2
SQL> Message was edited by:
Leo Mannhart
Craig you were faster

Similar Messages

  • How to display multiple reports at the same time

    Hi,
    I'm trying to display multiple reports at the same time, each one in separates tabs or windows using Forms 11g 11.1.1.6
    I have a button which has a call to a procedure which makes use of rp2rro library to show the specific reports, for example:
    call_report('report1');
    call_report('report2');
    call_report('report3');
    call_report('report4');
    The main problem is that, just the last report is been displayed.
    Is there some way to display report1, report2 etc in separate tabs or windows ??
    Regards
    Carlos

    You shouldn't have a problem calling different reports at once. As long as you're using Forms 11g they show up in different windows.
    The question is how you are calling the report.
    Here is how I manipulate it.
    After I pass parameters with the ADD_PARAMETER built-in I set some key values (destype, desformat, desname) with the RP2RRO's procedures.
    Finally calling RP2RRO.RP2RRO_RUN_PRODUCT and then WEB.SHOW_DOCUMENT passing the correct procedure parameters the report comes up in a window. If you repeat the above changing the appropriate variables (the report_name in the RP2RRO_RUN_PRODUCT and so on) you can get multiple reports in different windows.

  • How to integrate bing map for including or displaying multiple locations at the same time

    how to integrate bing map for including or displaying multiple locations at the same time

    Have you aware of the geolocation field that's been introduced with SharePoint 2013?  You can store location data within a list and then integrate this within Bing.  The second tutorial on this Bing team blog will show it well.
    https://www.bing.com/blogs/site_blogs/b/maps/archive/2013/03/26/connecting-a-sharepoint-list-to-bing-maps.aspx
    Steven Andrews
    SharePoint Business Analyst: LiveNation Entertainment
    Blog: baron72.wordpress.com
    Twitter: Follow @backpackerd00d
    My Wiki Articles:
    CodePlex Corner Series
    Please remember to mark your question as "answered" if this solves (or helps) your problem.

  • I want to display total count on the top of a Column in  business graphics

    Hi All ,
        How can I display total count of the column say for example no. of employees in a series of column chart type in business graphics.
    Any type of help would be much appreciated.
    Thanks
    Uday

    Hi Vishweshwara,
    following is the code i wrote. please check the correctness of the code.
    int seriescount = 0;
    for(int i=0;i<nodesize;i++){
    IGraphDataElement catele = gdNode.createGraphDataElement();
    switch(i){
    case 0:   
       if(wdContext.currentContextElement().getQ().equals("Q1")){
         catele.setCategory("Q1");
           catele.setKRA_Series1(Q1_KRA);
           catele.setApp_Pln_Series2(Q1_AP);
           catele.setRev_App_Series3(Q1_RA);
           catele.setEnd_Rev_Series4(Q1_ERP);
           catele.setApp_Procss_Series5(Q1_AIP);
           catele.setApp_overall_Series6(Q1_AOP);
           seriescount = seriescount+1; break;}
            break;
    case 1:       
       if(wdContext.currentContextElement().getQ().equals("Q2")){
           catele.setCategory("Q2");
           catele.setKRA_Series1(Q2_KRA);
           catele.setApp_Pln_Series2(Q2_AP);
           catele.setRev_App_Series3(Q2_RA);
           catele.setEnd_Rev_Series4(Q2_ERP);
         catele.setApp_Procss_Series5(Q2_AIP);
         catele.setApp_overall_Series6(Q2_AOP);
            seriescount = seriescount+1; break; }
                 break;
    case 2:       
    if(wdContext.currentContextElement().getQ().equals("Q3")){
         catele.setCategory("Q3");
         catele.setKRA_Series1(Q3_KRA);
         catele.setApp_Pln_Series2(Q3_AP);
         catele.setRev_App_Series3(Q3_RA);
         catele.setEnd_Rev_Series4(Q3_ERP);
         catele.setApp_Procss_Series5(Q3_AIP);
         catele.setApp_overall_Series6(Q3_AOP);
         seriescount = seriescount+1; break;}
                 break;
    case 3:   
    if(wdContext.currentContextElement().getQ().equals("Q4")){
         catele.setCategory("Q4");
            catele.setKRA_Series1(Q4_KRA);
         catele.setApp_Pln_Series2(Q4_AP);
         catele.setRev_App_Series3(Q4_RA);
         catele.setEnd_Rev_Series4(Q4_ERP);
         catele.setApp_Procss_Series5(Q4_AIP);
         catele.setApp_overall_Series6(Q4_AOP);
            seriescount = seriescount+1; break;}
                 break;
    case 4: if(wdContext.currentContextElement().getQ().equals("All")){
           wdContext.nodeGraphData().invalidate();
         wdContext.currentContextElement().setGraphVisibility(WDVisibility.NONE);
         wdThis.onActiondropdownaction(wdEvent);
    }default:
    wdContext.nodeGraphData().addElement(catele);
    Thanks
    Uday

  • Date range to be displayed  & Displaying multiple values on the report

    Hi,
    I have date range parameters, but I also need it to be displayed it on the report. Is there any way I can display it. E.G If a parameter is created one can drag and drop it on the report if it needs to be displayed on the report, I tried to do the same for the date range parameter but it does not work.
    Also If a parameter is created by selecting the option 'Allow Multiple Values', and if you drag and drop it on the report only the first value is displayed and the rest does not show. Has anyone tried this before and been successful in displaying multiple values in the report.
    Thanks in advance.

    Hi,
    A multi-value parameter is actually treated as an array in Crystal Reports.
    To display the values selected in the parameter, create a formula from the Field Explorer and type this code:
    Join({?ParameterName},",");
    Place this formula on the header or the footer sections of the report.
    Regarding the date range issue, please follow Sastry's advice and it should work fine.
    Make sure you're using the parameter in the Minimum and Maximum functions. For eg: If I was to create a date range parameter called OrderDate, my formula to show the start date would look like this:
    Minimum({?OrderDate})
    -Abhilash

  • How can i display units only for the result set

    hi
    i do not want to display units (example: $ or %) for my key figure columns but i want to display units to the result.
    how can i do that

    Hi Surya,
    I don't think it is possible to have both non-unit and unit in the same kf.
    One potential workaround to do this is to create a calculated key figure/ formula that use the NODIM function for single values. Example: NODIM(0AMOUNT). Then, create a calculated key figure/formula that computes overall result on the same kf and supresses individual values but does not use NODIM....perhaps this can help you work out a solution.
    Hope this helps.
    Regards,
    Petter
    Message was edited by: M Petter

  • How to display additional fields in the results a 'search user'?

    This may be a newb question but how can I display additional user attributes in the results of a user search in the admin console?
    i.e. more than just the standard fields of: User ID, First Name, Last Name, Status, Enable, Disable, Unlock and Delete.
    I would like to include some UDFs that I have defined for the create user form e.g. personnel number.
    Thanks,
    Bernie

    Thats not gonna work for sure. Thats to include additional attributes in the search input parameters drop-down. There is another procedure to do that, but not very sure if it works or not because once I was decompiling the code and found that it doesn't have an implementation. You can anyway try it out, the worst would be that you would not be able to see the column headings, but try atleast:
    And thats through the use of properties file. Open up ** and search for the following section-
    *#global.request.users.selectedListDisplayFields=*
    *#global.request.users.selectedListDisplayFields.lables=*
    Remove the comments and update it to below-
    global.request.users.selectedListDisplayFields=USR_UDF_EMPID
    global.request.users.selectedListDisplayFields.lables=global.xmlmetadata.users.USR_UDF_EMPID
    where USR_UDF_EMPID is the UDF and global.xmlmetadata.users.USR_UDF_EMPID is its associated translation.
    Thanks
    Sunny

  • Crystal Reports XI - Display multiple reports in the same viewer window

    Post Author: crystal_dev
    CA Forum: General
    Hello,
    We recently upgraded from CR 8 to CR XI. In CR 8, we were able to display multiple RPT files in the same run time viewe window and the reports would display in different tabs. However, we are not able to accomplish the same in the CR XI version of the crviewer.dll. Each report comes up in a different viewer windows which can be quite annoying to the user.
    Any way to do this in CR XI?
    Thanks.

    Hi Smitha,
    Wow - complicated reporting structure!   What the business wants can be done by creating direct reporting relationships between the positions - using the "005" relationship.  However, this is complicated and is difficult to maintain as there are probably frequent changes to this structure.  Also difficult to control if there are three chiefs in one org - who would approve vacations, pay raises or expense reports in Org Unit 1?  Per this structure any of the three could without consulting the others (all chiefs are equal). 
    Recommended:  Five separate Org Units - One for each Chief.  Org 1 has Position S1; Org unit 2 has position S2 as Chief and and position S5.  Org unit 3 has S3 as chief and S7 and S8 reporting to him; Org Unit 4 has S4 as chief; Org Unit 5 reports to Org Unit 4 and has S5 as Chief with S6 and S7 reporting to him.  You have S7 and S5 reporting to two different chiefs.  You may have a "dotted line" relationship for functional reports, but again recommend that there be only one individual who can grant pay increases, approve vacations, etc.  The dotted line or functional relationship can be handled via a "Matrix" relationship. 
    You and the business will have to sit down and decide the real "reporting" structure of this organization.  "Who reports to whom" and then build the structure around that.  You should not reproduce the structure as it has been just because many years ago with another system someone created a bunch of boxes.  SAP is flexible enough to handle any reporting structure, but for ease of maintenance, understandabilty, adaptability to Workflow and flexibility, please try to use the standard structure of Org Units with one chief and separate Org Units reporting to that one each with its own chief. 
    Paul

  • Can Numbers Display Multiple Views of the Same Table

    Hi,
    Excel and Appleworks both have a pull down tab on the vertical bar allowing multiple views into the same spreadsheet (table). Can Numbers do this?
    I have a set of calculations at the top of a spreadsheet that are based on years and years worth of data under the calculations (same column). I add data for each new event (the rows) and watch the calculations at the top of the data. Easy to do in Excel or Appleworks, but, I can't figure out how to do this in Numbers.
    Example:
    Spot1 Spot2
    Total 15 36
    Avg 5 12
    Jan 09 5 10
    Feb 09 6 20
    Mar 09 4 6
    Apr 09
    So... does Numbers allow the view "split" or multiple views that Excel and Appleworks allow?
    Thanks!
    Tom

    Question asked and responded several times:
    feature unavailable.
    For multiple views of a table there is an easy workaround as we may build a table whose every cells grab their contents from the 'master' one.
    _Go to "Provide Numbers Feedback" in the "Numbers" menu_, describe what you wish.
    Then, cross your fingers, and wait _at least_ for iWork'10
    Yvan KOENIG (VALLAURIS, France) mardi 1 septembre 2009 21:56:42

  • Bex report displays text Error in the result

    Hello,
    In my bex query result the text ERROR is displayed beside the value of a keyfigure.
    I'm not able to figure why this appears and how to find the error.
    Thanks.

    This is due to the absense of unit/currency against the key figure in the info provider.
    Maitain the currency/unit and then run the report. This should rectify the report error.
    Naveen.A

  • How do I display multiple recipients in the Sent Mail list view???

    In the list of sent mails, only one name (the first recipient) shows up in the "to" column. I would like to show as many names as there is room for, and not have to open the message itself to see multiple intended recipients.
    Other email clients do this as the default, but in Mail I just can't find the setting for how many names to display in that column.
    Help!!!!

    Terence,
    Thanks for the information.  Although this allowed me to open multiple windows, they are all show in a format too small (large thumb nails) to use.  I'm looking for a way to do a "split-window" function where two windows are shown (at the same time) larger enough to move between the windows and perform functions such as copy, paste, edit, or drag data from one to the other.
    Thanks

  • How do I display multiple seasons of the same TV Show?

    I have two seasons of the same TV Show which displayed fine, including artwork. But when I purchased the latest season of Stargate Atlantis (Season 4) it displayed the new episodes in the same grouping as Season 3. Additionally, it replaced the Season 3 artwork with Season 4. How do I replace the Season 3 episodes with the correct artwork? How do I display the Seasons separately, but sequentially, the same way Music albums are grouped and displayed?

    What version of iPhoto?
    The general process is to select the photo and print, select the printer, paper size and print size and click customize and under settings selec multiples copies of a photo (the preview will reflect this choice) and click print to print, make any printer specific selections and click print to print
    LN

  • HOW do you display multiple componants with the same id e.g. same generated image

    Hi,
    I would like to display two of these with the same id (canvas) which is an image generated through AS
        <canvas:DrawingCanvas id="canvas" >
            </canvas:DrawingCanvas>
    This is an annotation program im working on, and i would 2 of the same view of image, the reason being that the user can view a large and small scale version of the image he/she is working with
    I--------------------I    i----i   - small version
    I                        I    i----i
    I large version   I
    I                        I
    I____________I
    thanks
    art

    You don't need the object to have the same id to achieve your desired results, and you can't have the same object with the same id anyway.
    Just ensure whatever the user does is carried out on the larger and smaller image.
    If this post answers your question or helps, please mark it as such. Thanks!
    http://www.stardustsystems.com
    Adobe Flex Development and Support Services

  • Web services with multiple elements in the results

    We are using ASP.Net and LiveCycle Forms with LiveCycle Designer 7.0. LiveCycle forms is running on JBOSS (turnkey installation). Our problem is that if the web service returns multiple results e.g.
          £12.99
          Widget
          £0.99
          Grommett
    The form does not grow to accommodate the extra results. Has anyone had any experience of this issue. Adobe say it can be done but so far we have had no luck.

    <[email protected]> ha scritto nel messaggio <br />news:[email protected]..<br />> We are using ASP.Net and LiveCycle Forms with LiveCycle Designer 7.0. <br />> LiveCycle forms is running on JBOSS (turnkey installation). Our problem is <br />> that if the web service returns multiple results e.g.<br />> <products><br />>   <product><br />>      <price>£12.99</price><br />>      <description>Widget</description><br />>   </product><br />>   <product><br />>      <price>£0.99</price><br />>      <description>Grommett</description><br />>   </product><br />> </products><br />> The form does not grow to accommodate the extra results. Has anyone had <br />> any experience of this issue. Adobe say it can be done but so far we have <br />> had no luck.<br /><br />You have to create a subform that has flow content, then flag "repeat the <br />subform for each data item" (or something similar, I've not Designer <br />installed on this machine). Remember to save as dynamic PDF.<br /><br />Bye,<br />Alessio

  • Query to get total counts in the given scenario

    Hi,
    I am using Oracle 10g
    I have a table A with following data
    AgId     Trm     CD     S
    1000     100010     12-JAN     A
    1000     100019     20-MAR     A
    1000     100019     20-JUL     D
    1001     100011     25-JAN     A
    1001     100011     20-FEB     D
    1001     100011     23-MAR     A
    1001     100012     31-JAN     A
    1002     100013     14-FEB     A
    1002     100013     05-APR     D
    1002     100015     02-MAY     A
    1003     100014     03-MAR     A
    1003     100014     25-MAR     D
    1004     100016     22-MAY     A
    1004     100017     21-JUN     A
    1004     100018     01-JUL     A
    1005     100020     21-MAY     D
    1005     100020     21-JUL     A
    1005     100020     11-AUG     D
    Here the overall status of AgId '1000' is A as he is having atleast 1 Trm active
    Similarly, status of AgId '1001' is A
    status of AgId '1002' is A
    But,status of AgId '1003' is D as his trm is disconnected after activation(according to date column'CD')
    Then, status of AgId '1004' is A
    and finally status of AgId '1005' is D again as his trm deactivated, activated and deactivated at last
    So, considering these criteria can any one give me a query to get total no of AgId's who are 'Active' and similarly for 'Deactive'

    Hi,
    when you put some code please enclose it between two lines starting with {noformat}{noformat}
    i.e.:
    {noformat}{noformat}
    CREATE TABLE ... etc.
    {noformat}{noformat}
    Also do not forget to put correct statements. Your insert were missing semicolon at the end.
    Coming back to your problem, I assum that the current status of any trm is the latest status so I have done what follows:
    {code:sql}
    SELECT agid
         , trm
         , cd
         , s
         , ROW_NUMBER () OVER (PARTITION BY agid, trm ORDER BY cd) rn
         , COUNT (*) OVER (PARTITION BY agid, trm) rn_tot
    FROM a
    ORDER BY agid, trm, cd;
    Output:
          AGID        TRM CD        S         RN     RN_TOT
          1000     100010 12-JAN-12 A          1          1
          1000     100019 20-MAR-12 A          1          2
          1000     100019 20-JUL-12 D          2          2
          1001     100011 25-JAN-12 A          1          3
          1001     100011 20-FEB-12 D          2          3
          1001     100011 23-MAR-12 A          3          3
          1001     100012 31-JAN-12 A          1          1
          1002     100013 14-FEB-12 A          1          2
          1002     100013 05-APR-12 D          2          2
          1002     100015 02-MAY-12 A          1          1
          1003     100014 03-MAR-12 A          1          2
          1003     100014 25-MAR-12 D          2          2
          1004     100016 22-MAY-12 A          1          1
          1004     100017 21-JUN-12 A          1          1
          1004     100018 01-JUL-12 A          1          1
          1005     100020 21-MAY-12 D          1          3
          1005     100020 21-JUL-12 A          2          3
          1005     100020 11-AUG-12 D          3          3I have used to columns rn and rn_tot to find the latest entry for a specific agid, trm
    Using the query above I have done the following:
    WITH mydata AS
       SELECT agid
            , trm
            , cd
            , s
            , ROW_NUMBER () OVER (PARTITION BY agid, trm ORDER BY cd) rn
            , COUNT (*) OVER (PARTITION BY agid, trm) rn_tot
        FROM a
    SELECT agid
         , CASE WHEN SUM (CASE s WHEN 'A' THEN 1 END) > 0 THEN 'A' ELSE 'D' END s
      FROM mydata
    WHERE rn = rn_tot
    GROUP BY agid;
    Output:
          AGID S
          1000 A
          1001 A
          1002 A
          1003 D
          1004 A
          1005 D
    {code}
    Which is listing the agid and its status if at least there is one trm with final status 'A' for that agid.
    To sum up everything you can do simply like this:
    {code:sql}
    WITH mydata AS
       SELECT agid
            , trm
            , cd
            , s
            , ROW_NUMBER () OVER (PARTITION BY agid, trm ORDER BY cd) rn
            , COUNT (*) OVER (PARTITION BY agid, trm) rn_tot
        FROM a
    totdata AS
       SELECT agid
            , CASE WHEN SUM (CASE s WHEN 'A' THEN 1 END) > 0 THEN 'A' ELSE 'D' END s
         FROM mydata
        WHERE rn = rn_tot
        GROUP BY agid
    SELECT S, COUNT(*) cnt
      FROM totdata
    GROUP BY S;
    Output:
    S        CNT
    D          2
    A          4
    {code}
    Regards.
    Al                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

Maybe you are looking for