How do sum(field1+field2) in opensql?

I want sum more than one field in opensql,But the follow sentences are wrong:
SELECT SINGLE sum( hsl12 ) + sum( hsl13 ) FROM faglflext INTO ....
SELECT SINGLE sum( hsl12  + hsl13 ) FROM faglflext INTO ....

DATA: sflight_tab TYPE SORTED TABLE OF sflight
                  WITH UNIQUE KEY carrid connid fldate,
      sflight_wa  LIKE LINE OF sflight_tab.
SELECT *
       FROM sflight
       INTO TABLE sflight_tab.
LOOP AT sflight_tab INTO sflight_wa.
  AT NEW connid.
    WRITE: / sflight_wa-carrid,
             sflight_wa-connid.
    ULINE.
  ENDAT.
  WRITE: / sflight_wa-fldate,
           sflight_wa-seatsocc.
  AT END OF connid.
    SUM.
    ULINE.
    WRITE: / 'Sum',
              sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
    SKIP.
  ENDAT.
  AT END OF carrid.
    SUM.
    ULINE.
    WRITE: / 'Carrier Sum',
              sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
    NEW-PAGE.
  ENDAT.
  AT LAST.
    SUM.
    WRITE: / 'Overall Sum',
              sflight_wa-seatsocc UNDER sflight_wa-seatsocc.
  ENDAT.
ENDLOOP.
Rewads if helpful

Similar Messages

  • SELECT SUM( field1 field2 ) INTO C1

    Is that possible with a select statement in ABAP or do I need to sum each row by itself then add them together afterwords?

    Hi Craig,
    this is not possible with a select statement in ABAP. You can use the routine mentioned by you:
    DATA: C1 TYPE i,
          C2 TYPE i,
          total type i.
    SELECT SUM( field1 ) SUM( fiedl2 ) into ( c1 c2 )from tablename.
    total = c1 + c2.
    Of course you can use the exec sql statement proposed by Andreas, but you have to select for the cllient explicitly. There are some disadvantages for native sql, too:
    1. platform dependent
    2. no syntax check for the native sql part
    3. you bypass the SAP database buffer
    For more details refer to the online help about EXEC SQL.
    Cheers,
    Morten

  • How to sum the column in a table seperated by sign.

    How to sum the column in a table separate by sign.
    For Example:
    A B
    10 MOHAN
    -15 KUMAR
    -25 MARCH
    50 MAY

    SELECT  SUM(CASE SIGN(A) WHEN 1 THEN A ELSE NULL END) SUM_POSTIIVE,
            SUM(CASE SIGN(A) WHEN -1 THEN A ELSE NULL END) SUM_NEGATIIVE
      FROM  tbl
    /SY.

  • How to sum + group bp line items per a specific field?

    Hi,
    I found out about the SYS Numeric Query Based data definition, allowing me to sum the line items of a BP according to certain conditions.
    Now we have a more complex problem. We need to sum the line items of BP1 into the line items of BP2, grouping them by a given field. We know how to auto-create BPs on workflow events conditions, but we don't know how to sum the line items together.
    Is there a workaround?
    Thanks,
    S.R.

    We do not currently support QBDEs on line items so there isn't a way to sum values from other line items onto a line item.

  • How to sum in csv format

    How can I do a sum on a column in csv format? I am concatenating all columns in csv, so the resulting field is a string. Even if I convert it to a number, I am not sure how to sum a specific column. Any ideas?
    Thanks

    You would create the summary in the data model, and the value will be included in the output (whether that output be csv or whatever). If this doesn't help can you provide more details of the problem?
    Thanks,
    Danny

  • How to sum a column in SQL server??

    How do I sum a column called 'expenditureamount' in a sql table 'expenditureform', such that I get the total expenditure amount displayed in a text box??

    You can sum it with the SQL SUM function, of course, but what that has to do with how your program display that sum, I don't know. IOW, how you display is not anything related to JDBC, and how you SUM it is not anything related to JDBC. The first one is SQL (check on an SQL forum or Google for it) and the second depends on how you want to display it, and there are more appropriate forums than the JDBC one, for that.

  • How does SUM actually works

    Hi,
    I'm puzzled by how SUM actually works.
    I've got a table with the following fields:
    SET_OF_BOOKS_ID NOT NULL NUMBER(15)
    SUMMARY_CODE_COMBINATION_ID NOT NULL NUMBER(15)
    DETAIL_CODE_COMBINATION_ID NOT NULL NUMBER(15)
    TEMPLATE_ID NOT NULL NUMBER(15)
    LAST_UPDATED_BY NOT NULL NUMBER(15)
    LAST_UPDATE_DATE NOT NULL DATE
    ORDERING_VALUE NOT NULL VARCHAR2(25)
    Using the below, I was able to get the total value of all the ordering value.
    select sum(ordering_value) from gl_account_hierarchies where set_of_books_id = 1 and summary_code_combination_id = 1147;
    I was happy that I could get the total value but am puzzled as ordering value is of data type VARCHAR2.
    Is sum(ordering_value) a VARCHAR2 or a NUMBER then?
    I did a simple test, inserting the following record:
    insert into gl_account_hierarchies values(1,1024,1,2,3,'11-APR-2002','xyz');
    After committing, I double check by using the following statement:
    select * from gl_account_hierarchies where last_update_date = '11-APR-2002';
    and was able to retrieve the newly inserted record.
    But when I did another check with the following statement:
    select * from gl_account_hierarchies where set_of_books_id = 1 and summary_code_combination_id = 1147;
    I wasn't able to retrieve the newly inserted record.
    Why is that so? How does SUM actually works? Is the output of SUM a VARCHAR2 or NUMBERIC value?
    thanks in advance!!
    Yu S.S

    SUM() gives a number.
    What you have come across is an implicit data conversion. Basically the SQL parser doesn't reject your query as being syntactically invalid just because you're attempting a mathematical function on a non-numeric column. Instead when you execute your query SQL substitutes this
    select sum(to_number(ordering_value)) from gl_account_hierarchies where set_of_books_id = 1 and summary_code_combination_id = 1147;
    If you want to check this create a view
    create order_value as select sum(ordering_value) sum_val from gl_account_hierarchies ;
    and then desc it.
    Cheers, APC
    SUM(

  • How to sum

    Hi,
    May I know how to sum the units and amount in internal table? After summing, the value will be moved to new internal table.
    I try to do as below, but didnt get result. Perhaps something wrong? Can anyone help? Am very fresh in abap .. probably there are better ways to achieve this. Thanks.
    FORM GET_TOTAL .
    DATA : BEGIN OF WA_SUMM,
           PREV_LGORT TYPE LIPS-LGORT,
           TOTAL_LFIMG TYPE LIPS-LFIMG,
           TOTAL_STPRS TYPE MBEW-STPRS,
           TOTAL_TCOST TYPE LIPS-LFIMG,
           END OF WA_SUMM.
    DATA : IT_SUMM LIKE TABLE OF WA_SUMM.
    DATA : TOTAL_LFIMG TYPE LIPS-LFIMG,
           TOTAL_STPRS TYPE MBEW-STPRS,
           TOTAL_TCOST TYPE LIPS-LFIMG,
           PREV_LGORT TYPE LIPS-LGORT.
        SORT IT_OUTPUT BY LGORT.
        LOOP AT IT_SUMM INTO WA_SUMM.
          LOOP AT IT_OUTPUT INTO WA_OUTPUT.
          AT NEW LGORT.
              PREV_LGORT = WA_OUTPUT-LGORT.
              TOTAL_LFIMG = TOTAL_LFIMG + WA_OUTPUT-LFIMG.
              TOTAL_STPRS = TOTAL_STPRS + WA_OUTPUT-STPRS.
              TOTAL_TCOST = TOTAL_TCOST + ( TOTAL_LFIMG * TOTAL_STPRS ).
              MODIFY IT_SUMM FROM WA_SUMM TRANSPORTING PREV_LGORT TOTAL_LFIMG TOTAL_STPRS TOTAL_TCOST.
          ENDAT.
          ENDLOOP.
        ENDLOOP.

    See The sample code :
    Hi.
    TYPES: BEGIN OF G_I_DATA,
    PROFIT(4) TYPE C,
    COMPANY(4) TYPE C,
    ACCOUNT(10) TYPE C,
    AMOUNT TYPE P,
    END OF G_I_DATA.
    DATA: G_IT_DATA TYPE TABLE OF G_I_DATA,
    G_WA_DATA TYPE G_I_DATA.
    DATA: G_SUM_COMPANY TYPE P,
    G_SUM_PROFIT TYPE P,
    G_AMOUNT TYPE P.
    G_WA_DATA-PROFIT = '0001'.
    G_WA_DATA-COMPANY = '1111'.
    G_WA_DATA-ACCOUNT = 'ACCOUNT1'.
    G_WA_DATA-AMOUNT = 2000.
    APPEND G_WA_DATA TO G_IT_DATA.
    G_WA_DATA-PROFIT = '0001'.
    G_WA_DATA-COMPANY = '1111'.
    G_WA_DATA-ACCOUNT = 'ACCOUNT2'.
    G_WA_DATA-AMOUNT = 3000.
    APPEND G_WA_DATA TO G_IT_DATA.
    G_WA_DATA-PROFIT = '0001'.
    G_WA_DATA-COMPANY = '2222'.
    G_WA_DATA-ACCOUNT = 'ACCOUNT1'.
    G_WA_DATA-AMOUNT = 4000.
    APPEND G_WA_DATA TO G_IT_DATA.
    G_WA_DATA-PROFIT = '0001'.
    G_WA_DATA-COMPANY = '2222'.
    G_WA_DATA-ACCOUNT = 'ACCOUNT2'.
    G_WA_DATA-AMOUNT = 5000.
    APPEND G_WA_DATA TO G_IT_DATA.
    G_WA_DATA-PROFIT = '0002'.
    G_WA_DATA-COMPANY = '1111'.
    G_WA_DATA-ACCOUNT = 'ACCOUNT1'.
    G_WA_DATA-AMOUNT = 2000.
    APPEND G_WA_DATA TO G_IT_DATA.
    G_WA_DATA-PROFIT = '0002'.
    G_WA_DATA-COMPANY = '1111'.
    G_WA_DATA-ACCOUNT = 'ACCOUNT2'.
    G_WA_DATA-AMOUNT = 3000.
    APPEND G_WA_DATA TO G_IT_DATA.
    G_WA_DATA-PROFIT = '0002'.
    G_WA_DATA-COMPANY = '2222'.
    G_WA_DATA-ACCOUNT = 'ACCOUNT1'.
    G_WA_DATA-AMOUNT = 4000.
    APPEND G_WA_DATA TO G_IT_DATA.
    G_WA_DATA-PROFIT = '0002'.
    G_WA_DATA-COMPANY = '2222'.
    G_WA_DATA-ACCOUNT = 'ACCOUNT2'.
    G_WA_DATA-AMOUNT = 5000.
    APPEND G_WA_DATA TO G_IT_DATA.
    SORT G_IT_DATA BY PROFIT COMPANY ACCOUNT.
    WRITE: /6 'ProfitCenter', 20 'CompanyCode',
    34 'Glaccount', 48 'Amount'.
    WRITE: /6 SY-ULINE(50).
    LOOP AT G_IT_DATA INTO G_WA_DATA.
    AT NEW PROFIT.
    WRITE: /6 G_WA_DATA-PROFIT.
    ENDAT.
    G_AMOUNT = G_WA_DATA-AMOUNT.
    AT NEW ACCOUNT.
    WRITE: /34 G_WA_DATA-ACCOUNT,
    48 G_AMOUNT.
    ENDAT.
    G_SUM_PROFIT = G_SUM_PROFIT + G_WA_DATA-AMOUNT.
    G_SUM_COMPANY = G_SUM_COMPANY + G_WA_DATA-AMOUNT.
    AT END OF COMPANY.
    WRITE: /20 G_WA_DATA-COMPANY,
    34 'Totle',
    48 G_SUM_COMPANY.
    CLEAR G_SUM_COMPANY.
    WRITE: /6 '*******'.
    ENDAT.
    AT END OF PROFIT.
    WRITE: /6 G_WA_DATA-PROFIT,
    20 'Totle',
    48 G_SUM_PROFIT.
    CLEAR G_SUM_PROFIT.
    WRITE: /6 '*************************************'.
    ENDAT.
    ENDLOOP.
    Please use temporary Variable and clear that variable after processing
    Reward Points if it is useful
    Thanks
    Seshu

  • How to sum values from multiple lines in a DataTable?

    I have a Lookout program which uses a DataTable to allow users to write basic programs (relay on/off times, which relays change state, and pause times).  The DataTable cursor position changes to advance from one program stage to another.  
    What I would like to do is sum up the times from all the various stages.  Can anyone suggest how I might iterate through the DataTable using Lookout alone?  
    Thanks,
    Dave 

    I have tried to make 'loops' similar to that one but Lookout shows a message that iterations or loops for a variable are not allowed.
    You can use a sequencer but there are 2 inconvenients:
    1.- For a fast computer every step of the sequencer cannot be faster than 0.1 - 0.2 seconds. If you have many iteraciones, it will take some time.
    2.- The sequencer object has a maximimum of 100 steps.
    Ryan S. Here are questions for you:
    1.- Is there a way to add in the lks file statements and or functions using existing variables? What can be done and what not?
    2.- Is there a way to insert comments in the lks file?
    Thanks in advance.
    Rudy Lopez

  • "How to sum FKIMG in VBRK and VBRP Table with sample output

    Sir\Mam\Gurus ;
    I hardly found it difficult in resolving my program in getting the sum of FKIMG inside the VBRP and VBRK tables
    The scenario is that i have one Sales Order with multiple invoices . What i need to do is to sum up the fkimg or the quanitity of specific material regardless of how many invoices the material have in a particular SO
    Example I have Sales Order number 35678952 with
    3 invoices
    Invoice # 123 with material number mat1=12, mat2=5 , mat3=7
    345 with material number mat1=7, mat2=7
    678 with material number mat1=5, mat3=10
    Output shoud be
    salesorder# 35678952
    mat1 = 24
    mat2 = 12
    mat3 = 17
    Below is my Sample Codes:
    DATA : it_vbrp_details TYPE STANDARD TABLE OF wa_vbrp_details,
    ls_vbrp_details TYPE wa_vbrp_details,
    ls_vbrp_details1 TYPE wa_vbrp_details,
    lsfinal_vbrp_details TYPE wa_vbrp_details,
    it2_vbrp_details TYPE STANDARD TABLE OF wa2_vbrp_details,
    ls2_vbrp_details TYPE wa2_vbrp_details,
    it3_vbrp_details TYPE STANDARD TABLE OF wa_vbrp_details,
    itfinal1_vbrp_details TYPE STANDARD TABLE OF wa_vbrp_details,
    itfinal2_vbrp_details TYPE STANDARD TABLE OF wa_vbrp_details,
    itfinal3_vbrp_details TYPE STANDARD TABLE OF wa_vbrp_details,
    ls3_vbrp_details TYPE wa_vbrp_details,
    rtime1 TYPE i,
    rtime2 TYPE i,
    rtime3 TYPE i,
    s_erdate type d,
    scr_erdat type d,
    s_erdate = scr_erdat.
    CALL FUNCTION 'MONTH_PLUS_DETERMINE'
    EXPORTING
    months = 1 " Negative to subtract from old date, positive to add
    olddate = s_erdate
    IMPORTING
    newdate = new_date.
    """ This is another way manual adding by days
    CALL FUNCTION 'CALCULATE_DATE'
    EXPORTING
    days = +30
    start_date = s_erdate
    IMPORTING
    result_date = new_date.
    result_date = ddate.
    REFRESH: it_vbrp_details.
    SELECT
    vbrp~matnr
    vbrp~aubel
    vbrp~aupos
    vbrp~vbeln
    vbrp~kzwi1
    vbrp~kzwi2
    vbrp~kzwi3
    vbrp~kzwi4
    vbrp~kzwi5
    vbrp~kzwi6
    vbrp~mvgr1
    vbrp~mvgr2
    vbrp~mvgr3
    vbrp~mvgr4
    vbrp~mvgr5
    vbrp~knuma_pi
    vbrp~knuma_ag
    vbrp~mwsbp
    vbrp~vkaus
    vbrp~fkimg
    vbrk~vbeln
    vbrk~fkart
    vbrk~belnr
    vbrk~xblnr
    vbrk~vbtyp
    vbrk~kunag
    vbrk~fksto
    vbap~posnr
    INTO TABLE it_vbrp_details
    FROM vbrp INNER JOIN vbrk ON vbrkvbeln EQ vbrpvbeln
    where vbeln eq gt_data-vbeln
    where vbrpaubel eq vbapvbeln
    WHERE vbrp~posnr GE ''
    AND vbrk~vbtyp EQ 'M'
    AND vbrk~fksto NE 'X'
    AND ( vbrperdat GE s_erdate OR vbrperdat LE new_date OR vbrp~erdat IN s_erdat ) " + JP 09 19 2011 Additional Optimization
    ORDER BY aubel aupos .
    ORDER BY aubel aupos matnr.
    """" This where i need your help Sir\Mam\Gurus
    it3_vbrp_details = it_vbrp_details.
    SORT it3_vbrp_details BY aubel matnr fkimg kzwi1 kzwi2 kzwi3 kzwi4 kzwi5 kzwi6 aupos vbeln
    mvgr1 mvgr2 mvgr3 mvgr4 mvgr5 knuma_pi knuma_ag mwsbp vkaus fkart belnr vbtyp kunag fksto.
    LOOP AT it3_vbrp_details INTO ls_vbrp_details.
    COLLECT ls_vbrp_details INTO itfinal1_vbrp_details.
    APPEND ls_vbrp_details TO it_vbrp_details.
    ENDLOOP.
    kzwi1,kzwi2,kzwi3 is also been sum up
    Sir the output is something like this
    Sales Ord# Material Qty KWIZ1 KWIZ2 KWIZ3 MGVR1 VBELN
    1234       Mat1     24  23.2  22    12           LastInvoice#
    1234       Mat2     12  20.0  21    15           LastInvoice#  
    1234       Mat3     37  22.0  22    16           LastInvoice#
    5432       Mat1     30  25.0  23    15           LastInvoice#
    5432       Mat2     24  22.0  24    23           LastInvoice#
    5432       Mat3     20  18.0  20    12           LastInvoice#
    Hope you can help me as i cant hardy sleep thinking of this ...
    I will really appreciate your great help..
    Thanks !
    I will really appreciate your great help..
    Thanks !
    Moderator message: duplicate post locked.
    Edited by: Thomas Zloch on Sep 20, 2011 3:05 PM

    Hi,
      How you want to display the output?..
    If you want to display the output as mentioned below, then you have to use nested loop & dynamic field assignments to get result.
    Output column
    sales order     Mat1 Mat2 Mat3 ......
    1234               24    12     37
    Kindly let me know, if you have any questions
    Regards,
    S.Senthilkumar

  • How to SUM two count(*) values in a single sql tatement?

    How can I get a single SQL statement to sum two values from a count(*)
    I want something like this:
    SELECT COUNT(*) FROM MYTABLE
    UNION
    SELECT COUNT(*) FROM MYOTHERTABLE;
    but instead of getting
    111
    222
    I want to see the sum of the two values.
    333can such a thing be done with one statement. I know I can do stuff inside a BEGIN END and have vars but wonder if there is simple single statement solution.
    Thanks in advance,
    David Miller

    SQL> select count(*) from user_indexes;
                COUNT(*)
                      30
    SQL> select count(*) from user_tables;
                COUNT(*)
                      43
    SQL> select (select count(*) from user_indexes) + (select count(*) from user_tables)
      2  from dual;
    (SELECTCOUNT(*)FROMUSER_INDEXES)+(SELECTCOUNT(*)FROMUSER_TABLES)
                                                                  73

  • How to sum a specific category in pop up menu?

    For my expences i use a pop up menu
    how can i make a cell that will only add the numbers under ( eg. grocery )
    Thank you

    Trad,
    The function SUMIF was designed to do what you are asking.
    SUMIF
    The SUMIF function returns the sum of a collection of numbers, including only numbers that satisfy a specified condition.
    SUMIF(test-values, condition, sum-values)
    test-values:  The collection containing the values to be tested. test-values is a collection containing any value type.
    condition:  An expression that results in a logical TRUE or FALSE. condition is an expression that can contain anything as long as the result from comparing condition to a value in test-values can be expressed as a Boolean value of TRUE or FALSE.
    sum-values:  An optional collection containing the numbers to be summed. sum- values is a collection containing number, date/time, or duration values. It should have the same dimensions as test-values.
    Regards,
    Jerry

  • INSERT INTO table. . . SELECT field1, field2 From. . . .bug

    Hi,
    I should remember this but . . . bug with t-sql  using Insert Into  on a temp table.  It is unhappy with fields I'm trying to insert.
    It's probably the fact that I'm trying to using some default data w/ aliases for a couple of the fields. 
    Have a look at code please, and tell me how to correct. Thanks!
    DECLARE @OrderNo varchar(6)
    USE tempdb;
    set @OrderNo = '909773' ;
    IF OBJECT_ID ('#tmpNCGLITEMS') IS NOT NULL --how to get this to work with SSMS w/o reloading the qry window. i.e. how to release to delete????
    DROP TABLE #tmpNCGLItems
    use DEV_ORDERS;
    SELECT distinct od.lline as OrdLine, od.ldrcolor as ClrCode, od.ldrspec as SpecCode, ad.Addon_Mod_GL_Acct as ncGLCode
    INTO #tmpNCGLItems
    FROM OODETL od
    INNER JOIN [Dev_Products].[dbo].[Addon_Master] ad on od.lfg = ad.Addon_Mod_Mod_Code_ID AND ad.Addon_Mod_A_C_D_ID = 'C'
    WHERE od.LOrder = @OrderNo and ad.Addon_Mod_GL_Acct is not null
    select * from #tmpNCGLItems
    USE tempdb;
    IF OBJECT_ID ('#tmpNCGLITEMS1') IS NOT NULL
    DROP TABLE #tmpNCGLItems1
    USE DEV_ORDERS;
    CREATE TABLE [dbo].[#tmpNCGLItems1](
    [OrdLine] [char](4) NOT NULL,
    [ClrCode] [char](6) NULL,
    [SpecCode] [varchar](6) NULL,
    [ClrUPorDiscAmt] money NULL, [SpecUPorDiscAmt] money NULL,
    [ncGLCode] [varchar](10) NULL, [lPrice] money Null
    ) ON [PRIMARY]
    --insert into below is failing. Says fields don't match----Msg 213, Level 16, State 1, Line 33
    --Insert Error: Column name or number of supplied values does not match table definition.
    --but. . . I think I have 7 fields and I think the datatypes match?
    INSERT INTO #tmpNCGLItems1
    SELECT ordLine, ClrCode, SpecCode, 0 as [ClrUPorDiscAmt], 0 as [SpecUPorDiscAmt], ncGLCode,
    SUM(od.lextendprice) as lPrice
    FROM #tmpNCGLItems tmp JOIN OODETL od on tmp.OrdLine = od.lline
    WHERE od.lorder = @OrderNo
    GROUP BY ordLine, ClrCode, SpecCode, NcGLCode

    >> I should remember this but . . . bug with T-SQL  using Insert Into  on a temp table.  It is unhappy with fields [sic] I'm trying to insert. It's probably the fact that I'm trying to using some default data w/ aliases for a couple
    of the fields [sic: columns are not fields]. <<
    Temp tables are how a bad programmer fakes a scratch tape so his SQL can look like magnetic tape files. We do not like to materialize data  on the disk unless we have to. 
    And data element do not change names from table to table in a schema! Get rid of the aliases, even tho they are closer to ISO-11179 than the base table crap. 
    But you are an old FORTRAN programmer! Your "OODETL” is six uppercase letters as required by FORTRAN I; an SQL programmer would have used something like “Order_Details” instead. The mix of camelCase, FORTRAN and several other non-SQL languages is scary. 
    Why did you use MONEY? It is not portable and the math is wrong. Google it! Why do you think that “<something>_code_id” makes any sense? A data element can be a “<something>_code” or a “<something>_id” but never that hybrid disaster. 
    I would do this with VIEWs so that I know the data is always current. 
    CREATE VIEW NC_GL_Items (..)
    AS 
    SELECT DISTINCT OD.l_line, OD.ldr_color, OD.ldr_spec,
           AD.addon_mod_gl_acct  
      FROM Oodetl AS OD,
           Addon_Master AS AD
     WHERE ..;
    The SELECT DISTINCT should not be there. An account should not be NULL, etc. Why do you have more nulls in one table than entire accounting systems? Why do you set integer zero to an amount, which should be a decimal for money? 
    This is a crazy quilt that is clearly a bitch to maintain or even read. Can you clean it up or are you screwed? 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • Can't figure out how to sum only certain dates

    Hi all,
    Here is my issue: we use numbers to keep a running inventory of pieces in stock, and when a piece sells we mark it with the date sold. I'd love to be able to get a sum of monthly sales, but I can't figure it out. Would someone be kind enough to explain it to me like I was five? Here is a sample of our spreadsheet layout: http://i.imgur.com/sV1RU4s.png
    I can easily get a sum for the full column of C, but how do I enter the formula to sum only the sales from April, for instance.
    Thanks!!

    you can get function descriptions from Apple for free by downloading the function references here:
    http://support.apple.com/manuals/#productivitysoftware
    you will want to download the formula and function reference.
    OK...
    sumif() is a function that will sum values in a range based on a condition
    sumifs() is a similar function where multiple conditions
    both functions look at each row and only sum the values in a particular row when the condition(s) are all met.
    =SUMIFS(B,C,">="&E2,C,"<="&EOMONTH(E2, 0))
    let's work from the inside out...
    EOMONTH() returns the last day of the month you pass if offset by some number of months.  In this case I asked it to give the last day of the same month I passed in so the offset is 0.  The month I passed in is stored in E2.
    the basic concept is I only want to sum values in column B when the date in column C is in a paricular month.  said another way... I want to sum values in B where the corresponding date (in the same row) of column C is greater than or equal to the 1st day of the month AND is it also less than or equal to the last to of the month.
    SUMIFS() has several arguments a range to sum followed by a pair of arguments (test values range and a condition):
    SUMIFS(<SUM_RANGE>, <TEST_RANGE1>, <CONDITION1>, <TEST_RANGE2>, <CONDITION2>, etc )
    the sum range is column B
    test range 1 is the date column (column C)
    the condition is ">="&E1  which concatenates ">=" with the date in cell E1 to make a condition ">=Jan 1, 2013"
    test range 2 is the date column (column C)
    the condition is "<="&EOMONTH(E1, 0)  which concatenates "<=" with the date corresponding to the last day of the monthe in cell E1 to make a condition "<=Jan 31, 2013"
    I hope this helps

  • How to sum different column in the same table

    Hi everyone
    I would like to know how can I make the sum of different column in the same table using apex
    exple:
    TR_PROJ_BIL_TRIM.ENTPIDFISC as ENTPIDFISC,
        TR_PROJ_BIL_TRIM.EXEANNEE as EXEANNEE,
        TR_PROJ_BIL_TRIM.PROJBILTRIMT1PREV as PROJBILTRIMT1PREV,
        TR_PROJ_BIL_TRIM.PROJBILTRIMT2PREV as PROJBILTRIMT2PREV,
        trunc( TR_PROJ_BIL_TRIM.PROJBILTRIMT1PREV)+(TR_PROJ_BIL_TRIM.PROJBILTRIMT2PREV)
    from TR_PROJ_BIL_TRIM TR_PROJ_BIL_TRIM
    group by TR_PROJ_BIL_TRIM.ENTPIDFISC,TR_PROJ_BIL_TRIM.EXEANNEE
    but while trying to run this script i get this error message:"ORA-00979: not a GROUP BY expression"
    thanks for reading me and I hope to hear from you soon

    Hi,
    Your question do not have anything do with APEX.
    It is pure SQL question and you will get better answer this kind questions from SQL and PL/SQL forum
    You need have GROUP BY when you use aggregate functions like SUM.
    I assume you like just add two columns.
    Try
    SELECT ENTPIDFISC
        ,EXEANNEE
        ,PROJBILTRIMT1PREV
        ,PROJBILTRIMT2PREV
        ,trunc(PROJBILTRIMT1PREV) + (PROJBILTRIMT2PREV)
    FROM TR_PROJ_BIL_TRIM
    Regards,
    Jari

Maybe you are looking for

  • Can i move my itunes library to a sdhc card

    i am trying to use my pcmcia card in my mercedes, i cannot download my songs from itunes, anyone know how?

  • Help with pdf tasks

    Hello, I am trying to automate a couple of specific tasks with pdf files but I am having some trouble. At my job we are printing files to pdf but afterwards we must go back and edit the pdf files. Basically what we need to do is this (in order): 1) R

  • How to feed html content in Mail App from Indesign

    Anyone knows how Martha Stewart Everday Food Magzine achieved launching the ipad Mail App filled in with HTML body content directly from their digital magazine? At the end of each recipe, there is an email icon displayed, and when you click on it ipa

  • Unlimited space in Header Text of Purchase Order

    Hi Our customer wants to have unlimited space in the Header Text of the Purchase Order. Standard SAP Purchase order header text allows 15000 lines to be entered (approx 150 pages). After which the text needs to be split and entered. The same was sugg

  • I clicked a link in a spam email

    I clicked on an email telling me to check Facebook messages and when the page opened I saw Chinese characters.  What steps should I take now?