How to summarize ?

Hi all,
i have to develop a oracle sql-statement (no pl/sql) based on 1 table and a conditional sum. I have tried different case statements with group by, but i'm still not able to solve the problem. Any help appreciated.
The Columns:
id, value, flag, time
1, 100, a, 01.01.2005
1, 110, a, 01.02.2005
1, 120, a, 01.04.2005
1, 115, a, 01.04.2005
2, 105, b, 01.01.2005
2, 105, b, 01.02.2005
2, 130, b, 01.04.2005
Each id has only one flag a or b. For each id exists only one value per month.
flag a meens: the value is yet summarized
flag b meens: the value needs to be summarized
The Query:
List each id betwenn 01.01.2005 and 01.04.2005 and the value. For flag "a", take only the value of the last month, wich is 01.04.2005. It must be the last month, because of possible negative values before. For flag "b" summarize the values between 01.01.2005 and 01.04.2005 for each id.
Thanks and Regards,
Hen

If you can use analytic functions, then something like:
SELECT id, value, time
FROM (SELECT id, value, time,
             ROW_NUMBER() OVER (PARTITION BY id,
                                ORDER BY time DESC) rn
      FROM table
      WHERE flag = 'a' and
            time BETWEEN TO_DATE('01.01.2005', 'mm.dd.yyyy') AND
                         TO_DATE('01.04.2005 23:59:59', 'mm.dd.yyyy hh24:mi:ss'))
WHERE rn = 1
UNION ALL
SELECT id, SUM(VALUE), TO_DATE('01.04.2005', 'mm.dd.yyyy')
FROM table
WHERE flag = 'b' and
      time BETWEEN TO_DATE('01.01.2005', 'mm.dd.yyyy') AND
                   TO_DATE('01.04.2005 23:59:59', 'mm.dd.yyyy hh24:mi:ss'))
GROUP BY idIf you cannot use analytics, then something like:
SELECT id, value, time
FROM table o
WHERE flag = 'a' and
      time = (SELECT MAX(time)
              FROM table i
              WHERE o.id = i.id and
                    i.time BETWEEN TO_DATE('01.01.2005', 'mm.dd.yyyy') AND
                                   TO_DATE('01.04.2005 23:59:59', 'mm.dd.yyyy hh24:mi:ss'))
UNION ALL
SELECT id, SUM(VALUE), TO_DATE('01.04.2005', 'mm.dd.yyyy')
FROM table
WHERE flag = 'b' and
      time BETWEEN TO_DATE('01.01.2005', 'mm.dd.yyyy') AND
                   TO_DATE('01.04.2005 23:59:59', 'mm.dd.yyyy hh24:mi:ss'))
GROUP BY idHTH
John

Similar Messages

  • How to summarize Open sales order credit value

    Hi, friends.
    I am designing Add-on report about credit exposure.
    I found the relevant tables of Credit Limit in FD32
    KNKK
    S066
    S067
    Then, I would like to show the document details of open sales order credit value in the report.
    I tried to summarize the open sales order amount from VBAK, VAUK, VBAP, VBUP.
    However, it doest match to the amount in S066 table.
    Can anyone tell us how to summarize Open sales order credit value from SD documents?
    Regards,
    Yu

    Sudheer,
    You need to check the update rule given in the definition of the Credit control Area which you are using for credit management. If you want only the open deliveries then you need to have update rule 15 in the credit control area.
    In the credit controal settings, you need to have settings for the credit check at the delivery level.
    Hope this will solve your issue.
    Regards,
    Chetan
    Edited by: Chetan Gupte on Jul 15, 2010 8:56 PM

  • How to summarize the formula field for grand total

    Hi All
    Iam desinging a report in which iam facing a problem to summarize the formula field . This formula field contains sum calculation like
    formula name is @sales
    Sum ({@DTM200}, {@SaleMan})+Sum ({@DTM500}, {@SaleMan})+
    Sum ({@TM500}, {@SaleMan})+Sum ({@TM1000}, {@SaleMan})+
    Sum ({@HTM500}, {@SaleMan})+Sum ({@HTM1000}, {@SaleMan})+
    Sum ({@WM500}, {@SaleMan})+Sum ({@WM1000}, {@SaleMan})+
    Sum ({@CURD}, {@SaleMan})+Sum ({@Buttermilk}, {@SaleMan})+
    Sum ({@BULKWM}, {@SaleMan})+Sum ({@BULKTM}, {@SaleMan})
    the fields are summary fields and iam calculating all these fields to get the final result . Upto this it is working fine but finally i want to calculate the grand total of this formula '@sales' how should do this
    Thanks in advance

    Hi,
    If your formula name is @Sales you click the @Sales formula then Click Insert from Menu bar and click Summary.
    Then click Grand Total.
    Regards,
    Clint

  • How to summarize on multiple cross tabs

    Dear Sirs/Madams
    I have created a report in which I am using 2 queries.
    For each query I have created a crosstab which looks like this:
    Crosstab Query 1
                         Jan 2010      Feb 2010
    Keyfigure 1       X1             X2
    Keyfigure 2       Y1             Y2
    Crosstab Query 2
                         Jan 2010      Feb 2010
    Keyfigure 1       Z1             Z2
    Keyfigure 2       A1             A2
    I created a 3rd Crosstab in which I want to summarize (I created formulas for this):
    B1= X1+Z1
    C1= Y1+A1
    D1=X2+Z2
    E1=Y2+A2
    The query would look like this then:
    Crosstab Query 3
                         Jan 2010      Feb 2010
    Keyfigure 1       B1             D1
    Keyfigure 2       C1             E1
    However, the values coming through are not correct.
    Did anyone have this problem as well?
    If so, how did you solve this?
    Is there a way to solve this issue?
    Thanks in advance for your replies.
    Kind Regards,
    Joep

    Please re-post if this is still an issue or purchase a case and have a dedicated support engineer work with you directly:
    http://store.businessobjects.com/store/bobjamer/DisplayProductByTypePage&parentCategoryID=&categoryID=11522300?resid=-Z5tUwoHAiwAAA8@NLgAAAAS&rests=1254701640551

  • How do summarize data from several sheets

    How do I extract data from several sheets and summarize this data in a separate summary sheet?  What formula should I use?  When I used Excel I would use a formula like =John!G$5 for each cell I wanted from other sheets.  I'm having no luck trying to use the iWork Numbers suggestions.

    Hi Sid,
    "When I used Excel I would use a formula like =John!G$5 for each cell I wanted from other sheets."
    In Numbers,use:
    =John::G$5 to copy the contents of cell G5 on the Table named "John" to the cell containing the formula.
    Both cells must be in the same Document. If there is more than one Table named "John", the formula must also include the name of the Sheet containing the Table being referenced.
    (eg. =Sheet 1::John::G$5 )
    See also:
    consolidating data from several sheets
    Formulas Across Sheets (This one is missing it's illustrative images).
    Regards,
    Barry

  • Running Total - How to summarize a formula field?

    I'm sorry if this comes over as stupid but I have got myself quite messed up and am not 100% au fait with Crystal Reporting.
    The aim of my report is to calculate the costs of selected tests and to calculate a grand total of all tests at the end.
    I have created a group of  jobtests.TestTypeName
    Details
    1. testTypeName - to show Test Name that is being calcutaed - Database field
    2. Count ({jobTests.testTypeName}, {jobTests.testTypeName}) - to show number of tests of that type - this is a formula field
    3. Analysis1 - to show the cost of that test type - Database field
    4. {@CountTests/TestType} * {jobTests.AnalysisN1} - to show the number of tests per test type mulitplied by the cost of that test type - this is a formula field
    Report footer
    Count ({jobTests.testTypeName}) - to count the total number of tests
    MY PROBLEM - I need to see the sum of 4, this would be my grand total
    Trying to run the Running Total I can't get it to Summarize the field 4 because it is a formula field.
    What can I do?
    Thanks.

    You can't do a SUM on a formula that uses another aggregate function.  However, for both 4 and your grand total, you just need to SUM() (with ",{jobTests.testTypeName}" for the #4 calc), as the database field will be the cost for each test in each record.
    HTH,
    Carl

  • How to summarize a field from main window at the bottom

    I've a requirement in sapscript which is driven by standard program RVADOR01 to print certain quotation details.There is a field called tax code(kbetr) which
    is required to be displayed for each line item .
    Now i've also to summarize these tax code at the bottom of the page in another window.Here is the scenario
    In MAIN window:
    kbetr
      1     for 1st line item
      1     for 2nd line item
      2     for 3rd line item
      1     for 4th line item
      3     for 5th line item
      2     for 6th line item
    It have to summerise above tax code in FOOTER window as:
    kbetr
      1
      2
      3

    Hi anutosh,
    1. First check out if summary variables
       are already available in the standard drive program or not.
    2. Further to this, the TEXT ELEMENTS
      for printing the summary should also be available.
    3. This all logic / sequence of printing
       is absolutely
       contained in the driver program.
    4. If its not there,
       then probably u will have to
       copy the driver program,
       and do some enhancements/modifictiions.
    5. I don't think, by simply manipulating
       the sapscript layout, we can achieve this directly.
    regards,
    amit m.

  • How to  summarize count by bam report

    Hi All ,
    My Oracle BAM is 10g Release3 (10.1.3.3.0) build 35600 80
    I have question about technic of bam.
    My data objects is
    name time cnt
    1 RECEIVE 16:00 8
    2 RECEIVE 17:00 2
    from this picture
    Image:!http://www.pic2us.com/pic/4/416b474d1d282cfb6ce5e41d4ad44e5f.jpg!
    Normal report will display black line [8 2].
    But I want to summarize "cnt" and display like red line [8 10 (8+2)] .
    If I have new record of data object like
    3 RECEIVE 18:00 3 it must be [8 10 13]
    I see TechNote_BAM_RatioOfTwoAggregations.pdf but can't find any solution.
    Need help.
    Thank
    Weerawat

    Ok Thank I have solution
    I used oracle analytic before send to BAM
    Weerawat

  • How to summarize age ranges i.e 0-5, 6-10........?

    Post Author: SunilKanta
    CA Forum: General
    Hi,
    I am new to crystal reports, i am designing a report i.e cross tab report as shown below,
    AGE TABLE
    0-5
    6-10
    11-15
    16-20
    21-25
    26-28
    CLASS A Count
                     7
                   15
    CLASS B Count
                     7
                   15
    CLASS C Count
                    109
                 155
                 120
                   96
                   89
    Now my questions are,
    How to display age ranges i.e 0-5, 6-10,........?
    How to group ages in range and get the count or any summarized value ?
    Here i am passing three parameters to the report which are
    1. prmLowAge
    2. prmHighAge
    3. prmAgeBand
    Above shown sample is characterised with prmAgeBand = 5, prmLowAge = 0 and prmHighAge = 28.
    And if possible please try to find the solution for variable age bands.
    Please i am very desperate. Please help me in solving this .

    Post Author: Ishe
    CA Forum: General
    You can use a Do...While loop.  You can use the funtion below:
    LOCAL STRINGVAR AGEGRP;LOCAL NUMBERVAR AGECNT := 0;
    DO (AGEGRP := CSTR(AGECNT,0) + '-' + CSTR(AGECNT+5,0);AGECNT := AGECNT + 5)WHILE AGECNT < ;
    AGEGRP
    Also, you may want to use the following funtion to get , because the formula you were going to use would only compare the year of birth to the current year and ignore the number of months and days difference.
    Int(DateDiff("d",{table.BirthDate},CurrentDate)/365)

  • How to Summarize All items in A/R Invoice from 4 delivery documents

    Hi guyz,
    Is there a way to summarize all same items when copying 4 delivery documents to 1 a/r invoice? Summarizing all same items in one row.
    Regards,
    Michael

    Example:
    Delivery #1
    item 001
    item 002
    Delivery #2
    item 001
    item 003
    If this two delivery document is copy from A/R Invoice it should be:
    item 001
    item 002
    item 003
    What happens now is it list the items like this:
    item 001
    item 002
    item 001
    item 003

  • SAP BPC NW 7.0 How to summarize values for past periods

    Hi all,
    I have a following problem. I need to make adjustments for previous periods. And to create a new adjustment I need to take into account adjustments that were made in the past periods.
    I mean that I need to do smth like this u201CEVGET(Application,2009.NOV)u201D but instead of u201C2009.NOVu201D I need to use u201Cwhere time<2009.NOVu201D
    The question is how can I calculate adjustments values that were made in the past? (I need values for the whole history for the same dimension values).
    P.S.I had an idea to create the highest hierarchy node for time dimension and to use it in EVGET function instead of 2009.NOV but  this idea was blocked by architect.

    Hi Boris,
    I would try the following:
    - cell with "Start year" (eg: cell A1 with value "2005")
    - cell with "End year" (eg: cell A2 with value "2009")
    - Excel button linked to a macro or VB code that reads cells A1 and A2 and populates TIME MemberSet parameter with all the years in the reange (eg: "2009.DEC, 2008.DEC,2007.DEC,2006.DEC,2005.DEC" assuming YTD measure)
    - EVSUM function in AfterRange to calculate the sum of every year in the range
    Best regards.
    Joao

  • How to Summarize a Detailed Debtors Aging Report

    Dear All,
    I have written a Query for a Detailed Debtors Aging Report - i.e a report which lists ALL unpaid invoices. It works smoothly.
    I use SAP B1 8.8.
    Now, I want to create a Summarized Debtors Aging Report  which groups all the unpaid invoices for a particular debtor and displays only 1 row for each debtor.
    I use the following commands: SUM(), GROUP BY to modify the original query.
    A very simplified version of my Detailed report is in Screen 1.
    The modifications I made to it to convert it to a Summarized report are in Screen 2. It does not work!
    I have traced the error to the following:
    SUM ((SELECT T0.BalDueDeb - T0.BalDueCred WHERE DateDiff(mm, T0.TaxDate,@taxdt) = 1))
    AS '1 Mth Ago'
    This is the code I use to put the amount due in the appropriate Age Bracket.
    The SQL Error Message is:
    Cannot perform an aggregate function on an expression containing an aggregate or a sub query
    Could you please help me rewrite this so that it works?
    Thanks
    Leon Lai
    Screen 1 : The Original DETAILED report
    declare @taxdt datetime
    set @taxdt
    /*select 1 from jdt1 t0 where t0.TaxDate*/ = [%1]
    SELECT
    CASE
                 WHEN T0.Account = 1220101 THEN 'Prim Cust'
                 WHEN T0.Account = 1220102 THEN 'Fgn Cust'
                 WHEN T0.Account = 1220103 THEN 'Local Cust'
                 WHEN T0.Account = 1220104 THEN 'Staff Loan' 
                 WHEN T0.Account = 1220105 THEN 'Dep with TP'
                 WHEN T0.Account = 1220106 THEN 'Adv to Cust'
                 WHEN T0.Account = 1220108 THEN 'Sund Drs'
                 ELSE 'Error ! ! !'
    END AS 'Control A/c',
    T1.CardCode AS 'BP Code',
    T2.Notes2 AS 'BP Name',
    (T0.Debit - T0.Credit) AS 'Orig. Rs',
    (T0.BalDueDeb - T0.BalDueCred) AS 'Bal. Rs',
    (SELECT T0.BalDueDeb - T0.BalDueCred WHERE DateDiff(mm, T0.TaxDate, @taxdt) = 1)
    AS '1 Mth Ago'
    FROM JDT1 T0
    INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
    LEFT OUTER JOIN OCPR T2 ON T1.CardCode = T2.Cardcode
    LEFT OUTER JOIN OJDT T3 ON T0.TransID = T3.TransID
    LEFT OUTER JOIN OINV  T4 ON T3.TransID = T4.TransID
    LEFT OUTER JOIN ORIN  T5 ON T3.TransID = T5.TransID
    WHERE
    T1.CardType = 'C'
    and (Balance) != 0
    and (T0.BalDueDeb - T0.BalDueCred) != 0
    Screen 2 : The Modified SUMMARY report
    declare @taxdt datetime
    set @taxdt
    /*select 1 from jdt1 t0 where t0.TaxDate*/ = [%1]
    SELECT
    CASE
                 WHEN T0.Account = 1220101 THEN 'Prim Cust'
                 WHEN T0.Account = 1220102 THEN 'Fgn Cust'
                 WHEN T0.Account = 1220103 THEN 'Local Cust'
                 WHEN T0.Account = 1220104 THEN 'Staff Loan' 
                 WHEN T0.Account = 1220105 THEN 'Dep with TP'
                 WHEN T0.Account = 1220106 THEN 'Adv to Cust'
                 WHEN T0.Account = 1220108 THEN 'Sund Drs'
                 ELSE 'Error ! ! !'
    END AS 'Control A/c',
    T1.CardCode AS 'BP Code',
    T2.Notes2 AS 'BP Name',
    SUM ((T0.Debit - T0.Credit)) AS 'Orig. Rs',                 /* Added SUM()*/
    SUM ((T0.BalDueDeb - T0.BalDueCred)) AS 'Bal. Rs',         /*Added SUM()*/
    SUM ((SELECT T0.BalDueDeb - T0.BalDueCred
        WHERE DateDiff(mm, T0.TaxDate, @taxdt) = 1))    
        AS '1 Mth Ago'               /*Added SUM() PROBLEM IS HERE! */
    FROM JDT1 T0
    INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
    LEFT OUTER JOIN OCPR T2 ON T1.CardCode = T2.Cardcode
    LEFT OUTER JOIN OJDT T3 ON T0.TransID = T3.TransID
    LEFT OUTER JOIN OINV  T4 ON T3.TransID = T4.TransID
    LEFT OUTER JOIN ORIN  T5 ON T3.TransID = T5.TransID
    WHERE
    T1.CardType = 'C'
    and (Balance) != 0
    and (T0.BalDueDeb - T0.BalDueCred) != 0
    GROUP BY T0.Account, T1.CardCode, T2.Notes2                   /*Added GROUP BY*/

    Hi,
    Try:
    declare @taxdt datetime
    set @taxdt
    /*select 1 from jdt1 t0 where t0.TaxDate*/ = [%1]
    SELECT
    CASE     T0.Account
            WHEN 1220101 THEN 'Prim Cust'
            WHEN 1220102 THEN 'Fgn Cust'
            WHEN 1220103 THEN 'Local Cust'
            WHEN 1220104 THEN 'Staff Loan' 
            WHEN 1220105 THEN 'Dep with TP'
            WHEN 1220106 THEN 'Adv to Cust'
            WHEN 1220108 THEN 'Sund Drs'
            ELSE 'Error ! ! !'
    END AS 'Control A/c',
    T1.CardCode AS 'BP Code',
    T2.Notes2 AS 'BP Name',
    SUM (T0.Debit - T0.Credit) AS 'Orig. Rs',                 /* Added SUM()*/
    SUM (T0.BalDueDeb - T0.BalDueCred) AS 'Bal. Rs',         /*Added SUM()*/
    (SELECT SUM (T6.BalDueDeb - T6.BalDueCred) FROM JDT1 T6
        WHERE DateDiff(mm, T6.TaxDate, @taxdt) = 1 AND T6.TransID=T1.TransID)   
        AS '1 Mth Ago'               /*Added SUM() PROBLEM IS HERE! */
    FROM JDT1 T0
    INNER JOIN OCRD T1 ON T0.ShortName = T1.CardCode
    LEFT JOIN OCPR T2 ON T1.CardCode = T2.Cardcode
    LEFT JOIN OJDT T3 ON T0.TransID = T3.TransID
    LEFT JOIN OINV  T4 ON T3.TransID = T4.TransID
    LEFT JOIN ORIN  T5 ON T3.TransID = T5.TransID
    WHERE
    T1.CardType = 'C'
    and (Balance) != 0
    and (T0.BalDueDeb - T0.BalDueCred) != 0
    GROUP BY T0.Account, T1.CardCode, T2.Notes2                   /*Added GROUP BY*/
    Thanks,
    Gordon

  • How to summarize all the DUT test results such as Serialnumber, high limit, test result,low limit ,pass or fail to save to one excel table file? So i just open the excel file to see all the DUT report.For your help! any example.

    RT

    Here is an example of a sequence opening an excel document and creating a table. You have to slightly modify it, to save Serialnumber, high limit, test result etc. But this will be a good start.
    Hope this helps
    SijinK
    National Instruments
    Attachments:
    Write_Table_to_XL_and_Create_Chart.zip ‏9 KB

  • Summarize in numbers for ipad

    I do not know how to summarize in numbers for Ipad.
    I can sort without a problem. However if I want to summarize, I cannot do it.
    Please help
    RLK

    Here you are in a forum dedicated to Numbers for OSX.
    Your question is about Numbers for iOS which is a different application.
    Would be more efficient to ask in the forum dedicated to iWork for iOS.
    https://discussions.apple.com/community/app_store/iwork_for_ios
    Yvan KOENIG (VALLAURIS, France) jeudi 15 décembre 2011 17:42:58
    iMac 21”5, i7, 2.8 GHz, 12 Gbytes, 1 Tbytes, mac OS X 10.6.8 and 10.7.2
    My iDisk is : <http://public.me.com/koenigyvan>
    Please : Search for questions similar to your own before submitting them to the community

  • Summarize items in crystal report

    Hi all
    Any idea how to summarize Inventory Items of the same Item Code for printing in Crystal Report Design?
    The same item codes may appear in the same Sales Order or different Sales Order.
    Kedalene

    Hi Rajesh
    I don't really understand.
    Can you show me a sample dummy crystal report design with this kind of group formulas.
    <removed by moderator>
    Kedalene Chong
    Message was edited by: Oxana Noa Zubarev

Maybe you are looking for