SUM of the total in GroupBy

This is query that I'm running to group the category
SELECT cs.category as category,COUNT(*) AS total_cand
FROM candidate_session cs
WHERE cs.year = 2006
and cs.month = 'November'
and cs.category in ('DIPLOMA','RETAKE','CERTIFICATION')
GROUP BY csd.category
O/P
Category Count
DIPLOMA 100
RETAKE 200
CERTIFICATION 1100
Is there any way that the count can be sum-ed to give the total (1400) in the same query.Thanks.

Hi,
I hope it will work for your requirement.
SQL> ed
Wrote file afiedt.buf
  1  WITH tmp_qry AS (
  2  SELECT 101 CodeNo, '01/01/07' dt, 'SALES' Particulars    , 500.00 CB  ,0.00 DB ,500.00 Balance
  3  SELECT 102, '02/01/07', 'SALES'     , 1500.00  ,0.00 ,2000.00 FROM  DUAL UNION ALL
  4  SELECT 103, '02/01/07', 'COMMISSION', 200.00   ,0.00 ,2200.00 FROM  DUAL UNION ALL
  5  SELECT 104, '03/01/07', 'SALES'     , 1000.00  ,0.00 ,3200.00 FROM  DUAL )
  6  SELECT DT,
  7         SUM(DECODE(Particulars,'SALES',CB_AMT,0)) SALES,
  8         SUM(DECODE(Particulars,'COMMISSION',CB_AMT,0)) COMMISSION,
  9         SUM(DECODE(Particulars,'TOTAL',CB_AMT,0)) TOTAL
10  FROM (
11       SELECT DT,NVL(Particulars,'TOTAL') Particulars,CB_AMT
12       FROM (
13              SELECT  dt,Particulars,SUM(CB) CB_AMT
14              FROM tmp_qry
15              GROUP BY ROLLUP(dt,Particulars)
16            ) WHERE DT IS NOT NULL
17* ) GROUP BY DT
18  /
DT            SALES COMMISSION      TOTAL
01/01/07        500          0        500
02/01/07       1500        200       1700
03/01/07       1000          0       1000
SQL> Regards
Avinash

Similar Messages

  • How do you get the percentage of one number compared to the sum of the total in an array in ipad numbers

    How do you get the percentage of one number compared to the sum of the total in an array in ipad numbers

    On the iPad my example looks like this:
    To fill the formula down you tap cell and then Fill:
    And drag the bottom part of the yellow rectangle down:
    Wayne's example would look similar.
    SG

  • How to calculate the total of a calculated column in a list view at the end of the view?

    I have a view with the following columns ProductName, Quantity, Price, Total The total column is a calculated column which is the product of quantity and price. I want to place the sum of the total column by the end of the list view. I can do this with
    the price and quantity but not with the total column. how do I do this?

    You can use SharePoint Designer and calculate the total in xslt view. Refer to the following post for more information
    http://community.bamboosolutions.com/blogs/bambooteamblog/archive/2009/04/24/how-to-total-calculated-columns-in-a-sharepoint-list.aspx
    http://blog.metrostarsystems.com/2012/12/03/jennys-sharepoint-tip-sum-calculated-columns/
    Cheers,

  • Summing up subgroup totals

    In below table, the light blue rows, represents the subgroup I am trying to sum up.
    The value in the "Inventory Value" contains the latest inventory value for said inventory.
    Light green row is grouped by Store name, Light blue is grouped by inventory name. the expression in Inventory row for the inventory value column is  =First(Fields!InventoryValue.Value).
    Doing a store summation, sums up all detailed values. For example in Store A, instead of 70K, the sum would be 130K... double summing the toy soldiers and cute dolls inventory. Is there a way to do the "correct" summation or a different approach to this? Thanks!
    STORE
    TOTAL STORE INVENTORY VALUE
    INVENTORY
    % OF STORE INVENTORY
    INVENTORY VALUE
    WARNING DATE
    STORE A
    1,000,000.00
    TOY SOLDIERS
    2.00%
    20,000.00
    20,000.00
    11/5/2007
    20,000.00
    11/2/2007
    PLUSH TOYS
    1.00%
    10,000.00
    10,000.00
    11/5/2007
    CUTE DOLLS
    4.00%
    40,000.00
    40,000.00
    11/2/2007
    40,000.00
    10/31/2007
    1,000,000.00
    7.00%
    70,000.00
    STORE B
    10,000,000.00
    TOY SOLDIERS
    0.20%
    20,000.00
    20,000.00
    11/5/2007
    20,000.00
    11/2/2007
    PLUSH TOYS
    0.10%
    10,000.00
    10,000.00
    11/5/2007
    CUTE DOLLS
    0.40%
    40,000.00
    40,000.00
    11/2/2007
    40,000.00
    10/31/2007
    10,000,000.00
    0.70%
    70,000.00

    Tried the following approaches so far:
    =Sum(ReportItems!InventoryValue.Value)
    -- Errors out
    =Sum(Fields!InventoryValue.Value,"dsSummary")
    -- Created a new data set which only has the data from Light Green and Light Blue Rows (ommitted detailed rows)
    Returns ungrouped sums, meaning the total sum for all stores for Inventory Value
    =Sum(Fields!InventoryValue.Value)
    -- Double sums inventory values (sums up the inventory values from the detailed history)

  • How to calculate the total sum value of a particular field that repeats

    Hi All,
    I have the following Req...File----Idoc Scenario
    In the Inbound xml file i will get the Sales Order details with suppose 10 line items( 10 Orders)
    Each line item represents one one SO. So totally i wil have 10 Sales Orders in this file.
    <?xml version="1.0" encoding="UTF-8"?>
    <ns0:MT_Sales_Order xmlns:ns0="http://sap/Sales_Order">
       <Header>
          <COMP_CODE></COMP_CODE>
          <DOC_TYPE></DOC_TYPE>
           <SUPPL_VEND></SUPPL_VEND>
       </Header>
       <Item>
          <ITEM></ITEM>
          <MATERIAL></MATERIAL>
          <PLANT></PLANT>
          <QUANTITY></QUANTITY>
          <Amount></Amount> 
    </Item>
    In the above structure Item Segment will repeats as many no. of Sales Orders comes in a file.
    In a file if there are 10 Orders means the Item segment wil repeats 10 times.
    I have the Amount field in the Item Segment, each and every time that needs to be added to next Amount value that presents in the next Line Item.
    Finally i will have the Another separate field caled Grand Total, and i have to get the total summation of the 10 values of the Amount field at last.
    Can we achieve this using UDF or is there any way to do this
    REgards

    Hi,
    Do like this, actually in your case sum is taking place before the condition check for discount type
    do a little change in mapping
    DiscntType--removeContext--
                                              EqulsS-------IfWithoutElse----Amount---removecontext--then---SUM-
    Connstatnt(Value)
    --->GrandAmount
    Krishna, Check the same question asked by Rajesh in thread Calculate totals of segments that occur multiple times
    Thanks!

  • How to Hide rows in ALV without affecting total sum at the end of table?

    Hi,
    I need some help in hiding particular rows in an ALV Grid without affecting the total sum at the end of the table. I am trying to hide the rows that have negative quantities, but I still need those values so that the user can still compute for the total sums. Can anyone help? Thanks.
    Joseph

    Hi,
    Hopw this way you can hide the rows in the GRID.
    DATA:
      ld_column      TYPE lvc_fname,
      ld_hide          TYPE abap_bool.
    FIELD-SYMBOLS:
      <ls_entry>     TYPE any,
      <ld_fld>         TYPE any.
      ld_column = 'COL_1'.  " column which you want to suppress if everything is zero
      ld_hide     = abap_true.  " = 'X';  default hide column
      LOOP at <gt_outtab> ASSIGNING <ls_entry>.
        ASSIGN COMPONENT (ld_column) OF STRUCTURE <ls_entry> TO <ld_fld>.
        IF ( <ld_fld>   > 0 ).
          ld_hide = abap_false.  " display column because at least single value > 0
          EXIT.  " leave LOOP
        ENDIF.
      ENDLOOP.
      READ TABLE gt_fcat INTO ls_fcat
                           WITH KEY fieldname = ld_column.
      IF ( syst-subrc = 0 ).
        ls_fcat-no_out = ld_hide.
        MODIFY gt_fcat FROM ls_fcat INDEX syst-tabix.
      ENDIF.
    hop you will get the total with for those columns too.
    Regards,
    Madhavi

  • Sum() function not working properly. Instead of summing, its showing total count of the rows

    We have migrated one application from .net framework 1.0 to .net framework  2 (from Visual studio 2003 to Visual STUDIO 2005). Now after migration we are facing some problem related to the sum function in Crystal report 10. It is not working properly.
    So we migrated to Crystal report XI release 2 (though still using evaluation version for testing purpose), the problem is not yet resolved.
    The problem we are facing is while using the summary in the group field, it is showing the number of rows instead of the sum of the values.
    We have checked the same with min-max functions, and it is working properly with those.
    We have tried to make the sum by formula field. In such case, it is not showing any syntactical error but at execution time, it is throwing an error saying "A number field or currency amount field is required here".
    In the  the report the datatype of the field on which we are applying the sum function, is number, and in the table from where the data is fetched, the datatype is numeric(9,6).
    Any idea why sum function is not working ?
    I was browsing the net and saw running totals can be a work around for such summation issues in Crystal Report XI.
    Can you please provide insight of how to implement running totals for summation purpose in solving such issues.

    Hi,
    Running totals are more accurate than Summary Totals in Crystal.  Why? ...ask Crystal.  Anyway, just right click on Running Totals, create a new one, and enter you fields, etc. For group totals, it gives you a place to reset the totals for each group, etc.  Pretty self explainatory. 
    Jim

  • I have a dynamic table that calculates the sum of all rows, no issue.  I'm struggling with pulling out a subtotal though.  I would like to have a check box in each row  that flags those rows and gives the sum of their total.  Any help would be greatly app

    I have a dynamic table that calculates the sum of all rows, no issue.  I'm struggling with pulling out a subtotal though.  I would like to have a check box in each row  that flags those rows and gives the sum of their total.  Any help would be greatly appreciated.

    Here's something I threw together rq. The script is in the change event for the checkbox in the table. (Of course, you'll have to modify it to suit the names of your fields.)
    var rows = xfa.resolveNodes("tblAmounts.Row1[*]");
    var subtotal=0;
    for (i=0; i<rows.length; i++) if (rows.item(i).cbAdd.rawValue == 1) subtotal = subtotal + rows.item(i).nfAmount.rawValue;
    nfSubtotal.rawVlaue=subtotal;

  • Having Percentage on the Totals line instead of SUM

    Hi,
    I have a report with several number columns and several percentage columns. I need to show a totals line with grand totals for the number columns, and overall percentage for the percentage columns - how can I achieve this? I guess there is a more general question about showing any non-SUM summary function on the totals line, such as AVG, COUNT, MIN, MAX etc.
    I could do it as a UNION I suppose but then I have the problem of formatting the totals line, and this wouldn't really work for break groups, only a grand total.
    Any ideas?
    Steve

    You might want to look into the CUBE, ROLLUP and GROUPING SETS (OLAP) extensions to the GROUP BY clause in SQL. They generate intermediate subtotals, break totals, grand totals, etc using plain SQL.
    Here is a quick example of what I mean
    http://htmldb.oracle.com/pls/otn/f?p=24317:190
    I have chosen to use SUM(SAL), AVG(COMM) and MAX(SAL) as the aggregates, you can modify this as per your requirements.
    The query is
    select
    empno,ename,job,deptno,
    sum(sal) sum_sal,
    avg(comm) avg_comm,
    max(sal) max_sal
    from emp
    group by rollup(empno,ename,job,deptno)
    having  grouping_id(empno,ename,job,deptno) in (0,15)The GROUPING_ID gives a binary "bitmap" of which columns are showing a detail row vs. a aggregate/super-aggregate row. In this case, we want to show the lowest level of detail (0) and the highest grand total (15=binary 1111 or all bits turned on)
    Again, you can tweak this to show intermediate subtotals, just take out that HAVING clause to see what you get and modify as needed.
    Hope this helps.
    Message was edited by:
    Vikas

  • Total Baseline Hours For A Resource Does Not Equal the Sum of the Weekly Baseline Hours for that Resource

    Hi,
    I am using Project Server 2010. I have a project schedule that has been baselined and no actual work has been charged to it. The project has 3 resources. I am in the Resource Usage View. With 2 of the three resources, the hours in the Baseline Work Column
    on the left side of the view do not equal the sum total of weekly hours in the Timephased Grid. For instance, for resource JB the Baseline Work hours column says 1,392. When I total his weekly hours in the timephased grid I get 1368 hours; a variance
    of 24. Resource RS has 794.5 hours in the Baseline Work column but the sum total of his weekly timephased grid hours is 710.5, a variance of 84 hours. In both cases, the sum of the hours in the timephased grid is less than the hours in the Baseline Work column.
    What would be causing this? (I am cutting and pasting the weekly hours in the timephased grid into Excel and using the Excel sum function total).  Is there a better timephased view I should be looking at to try to find the "missing
    hours"? I have seen this before in project and it really has me stumped. Thanks.
    Judy Washington

    Hi Judy,
    I could not reproduce your issue. Is your Project Server patched with the latest SP and CU?
    Also can you reproduce this unexpected behavior with another project?
    Can you split your screen from the resource usage view, display the resource form and click right on the grey part selecting "schedule"? Then you'll have the scheduled start and finish dates for the resource's assignments. This is to be sure that
    you are not missing any parts of the assignments due to a wrong zoom in the timephased grid.
    Hope this helps,
    Guillaume Rouyre, MBA, MCP, MCTS |

  • Discoverer  report does not sum up the column

    Hi All,
    I am running the discoverer report from discoverer desktop and was
    trying to use the sum function to sum the total amount of the report.
    The sum function does not work and it only display Cell
    Sum: (blank) with no actual data.
    When i checked the report details some columns are calculated based on the columns which i want to sum up.
    Any ideas please share with me
    Thanks in advance.

    b) What is the difference between sum and cell sum? Well, I certainly won't claim to be a Discoverer guru. From what little I have seen, the practical result is not any difference really between the two. SUM of a calculated row is adding up the calculation to the total. Whereas cell sum is like adding up the individual values behind the calculation you see. The distinction makes more sense when you have SUM DISTINCT and CELL SUM DISTINCT being involved. Then you will see a difference in the calculated total. But for SUM and CELL SUM itself, I have not seen any difference between the two, but I am still pretty new to Discoverer.
    e) Aggregate field from a folder. Well, this may be one where you have to play around with your own data to understand. Let me try to give you a simple example. Let's say you have a sales table with 100 rows. You have sales data for 5 cities, and each city has 20 rows of sales history. If you pick Sales Dollars Detail and City Name for your workbook and run, you will get 100 rows in your result (complete detail listing). So that is what happens with no aggregation. Now, instead of doing Sales Dollars Detail, you pick Sales Dollars Sum (the same thing as saying SUM(Sales Dollars) in an SQL statement). Run the workbook. You will now get 5 rows of data, instead of 100 rows of data. You will get one row for each city. If you look at the SQL that Discoverer generates, you will see that it has now done a GROUP BY in the SQL statement. Notice I have not said anything about DISTINCT (just trying to keep things simple).
    Now, lets say you do a workbook for City, Part Number, and Sales Dollars Sum. Run the workbook. You get a summarized result (say maybe 10 rows of summary data this time). If you look at the Discoverer SQL, the GROUP BY is now by city and part number, automatically doing that because you picked the SUM version of sales dollars.
    Now lets say you add Sales Units Detail to the workbook. Discoverer will give you a warning message that you are have both an aggregate and a non-aggregate and that you may end up with unpredictable results. Run the workbook. You will be back to 100 rows, because you specified sales units in detail.
    Most of the time I do not want to see detail rows in a workbook. So most of the time I am picking the SUM aggregate for an amount item.
    Hope this explains things a bit. Sounds like maybe you need to take the Discoverer Create Queries and Reports class. Would help you understand these things better. Good luck.
    John Dickey

  • Calculating the total of one column within a GridView

    Hello Everyone!
    I have created a Grid with 6 columns. The 6th column contains monetary values. I have set 'ShowFooter' to 'True' and have styled my footer however there is currently no data in the footer. What
    I'm looking to do is calculate the total of the 6th column and put the value within the footer at the bottom of the 6th column - I'm not sure how to go about this so any assistance would be much appreciated.
    Thank you

    Good morning Griffs, 
    Check this out...http://stackoverflow.com/questions/19808855/calculate-the-sum-of-gridview-column-data-and-store-its-value-in-a-variable
    Danny Rosales .NET Developer

  • Calculating and Displaying the Total for a field

    Hi all,
    I have a template that must have a field's total at the end of each page. I use <?add-page-total: InvAmt;’ ACCOUNTEDDR’?> for calculating the sum and<?show-page-total:InvAmt; 'C9G990D00';'(C9G990D00)'?> for showing the total. Its coming up properly.
    But on the last page i need the total of all the pages. I tried putting up <xdofo:inline-total display-condition="everytime" name=" InvAmt "> <xdofo:show-carry-forward name="InvAmt " format="99G999G999D00"/> in the footer but its printing the whole code as such. I tried to do a sum <?sum (ACCOUNTEDDR)?> after the for-each, but its returning a NaN. I couldnt find a solution for this.
    Please help.

    The NaN display that you get is probably due to some nulls. Filter out the nulls: <?sum(ACCOUNTEDDR[.!=''])?>
    For last page only content, take a look at the section "Last Page Only Content" in the guide here: http://download.oracle.com/docs/cd/E12844_01/doc/bip.1013/e12187.pdf
    Hope that helps.
    Bipuser

  • Problem with subtotal, and the total icon is not displayed at the toolbar

    Hi all,
    I'm currentlyhaving difficulties working with the subtotal and the grandtotal. I have the code in the right place like the sort table
      CLEAR k_sort.
      ADD 1 TO k_sort-spos.
      k_sort-fieldname = pv_fieldname.
      k_sort-up        = c_x.
      k_sort-subtot    = pv_subtot.
      APPEND k_sort TO i_sort.
    and the fieldcatalog
      CLEAR k_fieldcat.
      add 1 to k_fieldcat-col_pos.
      k_fieldcat-fieldname  = pv_fieldname.
      k_fieldcat-tabname    = c_tabname.
      k_fieldcat-seltext_l  = pv_seltext.
      k_fieldcat-outputlen  = pv_outputlen.
      k_fieldcat-datatype   = pv_datatype.
      k_fieldcat-do_sum     = pv_dosum.
      APPEND k_fieldcat TO i_fieldcat.
    but it didn't seems to show both the total and subtotal. Even the icon is not displayed at the ALV toolbar. The field which I need the total is a currency field. I even try other fields (interger fields) but with no luck. I'm using REUSE_ALV. Any help is greatly appreciated.

    hi,
    In field catalog for the particular column which you want to sum make that as 'X'.
    say
    WHEN'MATNR'.
    it_fcat-do_sum = 'X'.
    CALL FUNCTION 'REUSE_ALV_GRID_DISPLAY'
           EXPORTING
                i_callback_program     = report_id
                i_grid_title           = ws_title
    *            i_callback_top_of_page = 'TOP-OF-PAGE'
                is_layout              = wa_layout
                it_fieldcat            = i_fieldcat[]
                it_sort                = i_sortcat
                i_save                 = 'A'
                it_events              = i_events
           TABLES
                t_outtab               = i_reportdata1
           EXCEPTIONS
                program_error          = 1
                OTHERS                 = 2.
      IF sy-subrc <> 0.
    This will enable.

  • ALV List Display - Is it possible to sum up the subtotal values of  field

    Hi Experts,
    We hav a requirement to do subtotals of the price field for each unique PO Line item, and also to sum up the subtotal values ie. only the subtotal values needs to be added irrespective of the repetation of the po line items in the report.
    PO Number                  PO Item              Price
    XXXXXXXX                 10                      20
    XXXXXXXX                 10                      20
      Subtotalled                                          20
    YYYYYYY                 10                      10
    YYYYYYY                 10                      10
      Subtotal showing                                10  
    We want the total of price to be           30 ie (Subtotal value of XXXX, 10 = 20 and YYYYY,10 = 10 ) but currently do_sum is been used in the fieldcat of the report which displays all the occurances of the record... = 60(202010+10)
    Kindly help asap.
    Thanks,
    Rosy

    Hi rosy,
    the question pops up to why you have duplicates in the display table. If you
    DELETE ADJACENT DUPLICATES FROM
    the output table, everything should be fine.
    Regards,
    Clemens

Maybe you are looking for

  • Help needed for SQL query

    hello , I am a beginner in terms of writing sql queries. I hope some body can help me out. I have two tables mysql> desc user_group_t; ---------------------------------------------------+ | Field | Type | Null | Key | Default | Extra | --------------

  • How to center this text in wordpress PHP file?

    Hi, I am trying to center the text on the bottom of my blog.  Site Admin Log out WP These three elements above are aligned left and looks really bad, looks like the problem is on my footer.php, a container called footermenu, but I can't figure out wh

  • Deleteing 110 million records..!!!!!!!1

    I have got a table which has 120 million records out of which only 10 million records are usefull. Now I want to delete the remaining 110 million records with the where condition. I spoke to my DBA and he said this has it will take around 2 weeks or

  • I need some serious professional help with upgrading my MAC

    Hello all here at Apple Discussion, I have been wanting to upgrade my PowerMac G4 for quite sometime now. I just built two new advanced PCs for my Digital Art and Gaming, but I still need my Mac for all of the Video Editing, and Visual Effects I do.

  • Dutch Denim update (country variant) gives 8018830...

    The Denim update (country variant) finally arrived for the 630 in the Netherlands, a couple of days ago. But I can't seem to get this update installed as it shows a 8018830f error when preparing the installation, after a succesful download. Now I kno