Help w/Sum column

The following query will return the last 10 records of a table where the record date falls within the first and last of the current month:
<pre>
SELECT *
FROM (
SELECT p_id, f2, amount, date1
FROM mytable a
WHERE a.date1
BETWEEN TRUNC(SYSDATE,'MM') AND LAST_DAY(SYSDATE)
ORDER BY a.date1 DESC, amount DESC
WHERE rownum <= 10;
</pre>
Now I need to add a column to this query resultset that will have SUM(amount) for ALL the records in the current month (not just the last ten). The idea is that I can hide that last column from my application but still have the field available (total) to add as a footer.
I tried (eliminating the semi-colon after the ten and then appending the following code to the query above:
UNION
SELECT '1','2,SUM(amount), SYSDATE
FROM anothertable b
WHERE b.date2
BETWEEN TRUNC(SYSDATE,'MM') AND LAST_DAY(SYSDATE);
...but all that this does is adds a first record to the recordset with constants "1" and "2" to the first two fields, the desired total sum for the whole month, and the current date. However, I want that sum as another column (even though it may be there ten times), not at the top as another record.
How can I do this?
Thx!

You could just add another subquery, like so:
SELECT *
FROM (
  SELECT p_id, f2, amount, date1,
      ( select sum(amount) from mytable
        where date1 between trunc(sysdate,'mm') and last_day(sysdate)) amount_total
  FROM mytable a
  WHERE a.date1
  BETWEEN TRUNC(SYSDATE,'MM') AND LAST_DAY(SYSDATE)
  ORDER BY a.date1 DESC, amount DESC
WHERE rownum <= 10;

Similar Messages

  • Need help with summing column when using if-then-else

    Using logic
    <?xdofx:if INVOICE_BILL_AMT_IN_INV_CURR is null then INVPROC_BILL_AMOUNT else INVOICE_BILL_AMT_IN_INV_CURR end if?> for column field.
    Having trouble summing the column using the logic above.
    Any suggestions would be very much appreciated.
    Thanks,
    Nancy

    Thanks Tim,
    That worked. Got rid of my error. However, if the field is null (=''), I get a total.
    11.05 + 1429.70 = 1440.75
    If the not null (!='') I am not getting a total.
    103.74 + 173.13 =
    BTW, recently took XML class. Leta Davis highly recommended your blog and I have gotten a lot of great tips from it.
    Thanks,
    Nancy

  • Summing Columns

    I am using LiveCycle Designer version 8 and I am very new to this program. I need help in summing a column. I can sum the rows but I can not seem to get the columns to sum. I have been trying to use FormCalu to add the formula. I have check for the common errors of referencing or mispelling a cell in the column that I am trying to sum. Any help would be greatful. Thanks,

    Hi both of you,
    Are there any joins involved in the report where you're trying to add the sum? If so, please check the master-detail definition in the join. If it's the wrong way around, then Discoverer can refuse to calculate a total, because there is a risk of "summing apples and bananas".
    Other option is that one of the functions involved can result in a null value (litteraly: maybe it doesn't show any nulls, but the function could theoretically result in null), if so then Discoverer also doesn't sum them up. Reasoning is that no aggregations are done on "potentially null containing items". This is very good if you're trying to calculate an average (because how on earth would Discoverer know how to handle nulls in an average), but it's a bit annoying with a sum... Anyway, change the functions so that they can never ever result in null, or write a view around it to "wrap" the nulls or... come up with anything to avoid nulls.
    (before you go into this, first remove the data resulting from functions, if possible, to make sure that the sum does indeed get calculated if then, so you know for sure that the functions are causing it now).
    Regards,
    Sabine

  • Web dynpro for abap how to create a customize search help in alv column

       hi:
          Web dynpro for abap how to create a customize search help in alv column and put search help value into alv column?
          Are there specific examples ?
          thanks!!

    HI:
       I want to created a freely programed help which include date&time,and put help value to alv column.
      I have created a freely programed help in web dynpro for abpa application,I refer:
      **************** - WebDynpro for ABAP
      but have a problem!
       If you focus on the the input field in the first row, you get the value help
    However if  I go to the second row and focus on the same input field in this column, I don't get the value help:
    What is a good way to solve similar problems?
    thanks

  • Please help me  one column i have this data col1

    Please help me
    one column i have this data
    col1
    Hi this is <SPAN style="FONT-SIZE: 18pt" data-mce-style="font-size: 18pt;">Rabindra.<SPAN style="FONT-SIZE: 10pt" data-mce-style="font-size: 10pt;">R u <SPAN style="FONT-SIZE: 18pt" data-mce-style="font-size: 18pt;">remember</SPAN> me .</SPAN></SPAN
    dfg sdfgfdsg sfdgsdf gsfdgsdfsd <SPAN style="FONT-SIZE: 18pt" data-mce-style="font-size: 18pt;"><STRONG>Rabindra</STRONG></SPAN
    i need like
    col1
    Hi this is Rabindra.R u remember me.
    dfg sdfgfdsg sfdgsdf gsfdgsdfsd Rabindra

    Hi,
    If str is a string, and you want a version of it without any of the tags (that is, without the '<' or '>' characters, or anything between them), then you can use REGEXP_REPLACE, like this:
    REGEXP_REPLACE ( str
                  , '<[^>]+>'

  • How to get the F4 help for table columns ..

    Dear All,
    Here I have created table with cell editors of INPUT FIELD .
    And I would like to provide the f4 help for those columns .
    Here I have checked the node , which i have binded to the table, there input help mode is set to Automatic and search helps are also attached for that node .
    But in the table I am not getting the F4 help . Where as if i create the input fields invidually i am able to see the F4 help .
    But for table column I am unable to find..
    Help me regard this...
    Thanks & regards,
    Veerednra Nath

    Hi,
    In debugging , the I have seen the node info attributes list ( VALUE_HELP_ID and VALUE_HELP_MODE ) .
    For you understanding, Here I am giving the values which contains ,
    VALUE_HELP_ID contains the AUTO:VBUK
                                                    AUTO:VBUP
                                                    AUTO:MAT1
                                                    AUTO:H_T023
    and
    VALUE_HELP_MODE contains the  all Zeros for all the four attributes .
    Hope I have given correct inputs .
    Thanks & Regards,
    Veerendra Nath

  • I need help on sum

    Post Author: genesis
    CA Forum: Formula
    Hello I need help on sum
    this is my example
    W/O      Status         Datew1681     008   05/01/2007 7:00 amw1681     009   05/01/2007 8:10 amw1681     010   05/01/2007 9:00 am
    I need to sum how long to to move from step 008, 009 and 010
    W/O      Status          Datew1681     008   05/01/2007 7:00 amw1681     009   05/01/2007 8:10 am  1:10  Hourw1681     010   05/01/2007 9:00 am  0:50 minutes
    The table & field that hold date value is WO_TASK_STATUS.ENTRY_DATE

    Post Author: bryanflora
    CA Forum: Formula
    Insure you already order the data in W/O then Status.Write a formula like this:{WO_TASK_STATUS.ENTRY_DATE} - Previous({WO_TASK_STATUS.ENTRY_DATE})Because it get the field value from the previous row, so in right order is important.

  • Sum Column Script

    This is not working; THANK YOU to anyone kind enough to point out what's missing.
       <field h="5.293mm" name="IncomeTotal" w="19.134mm" x="54.478mm" y="126.775mm">
                <ui>
                   <textEdit>
                      <border hand="right" presence="hidden">
                         <?templateDesigner StyleID aped0?></border>
                      <margin/>
                   </textEdit>
                </ui>
                <font size="11pt" typeface="Myriad Pro"/>
                <para vAlign="middle"/>
                <traversal>
                   <traverse ref="TextField4[3]"/>
                </traversal>
               <sum(IncomeTotal [Income1, Income2, Income3, Income4, Income5, Income6, Income7, Income8, Income9])>
             </field>

    Hi,
    First of all I would not recommend inputting script directly in the XML Source. If you go to the Design View you can open the Script Editor (5) from the Windows menu. I would recommend making it larger, so that you can see a few lines of script:
    You can see an example here for referencing objects in both JavaScript and FormCalc. This also includes an example for summing columns: http://assure.ly/kUP02y.
    Niall

  • Help Needed to Sum Column in Fixed Table

    I am new to LiveCycle.  I need to sum a column in a fixed table.  My rows are summing correctly.  I have tried every formula on the web both in FormCalc and Javascript.  I've cut and pasted script from Adobe templates and from forms on the web.  Nothing is working.  Each change produces a new set of errors.  The Hierarchy is:  (untitled Subform) (page 2), Table 2, Header Row {Header Row contains Year 1, Year 2...Year 5}, Row1 {Row1 contains Text Title, Cell2, Cell3, Cell4, Cell5, Cell6, (untitled Numeric Field) which is a calculated sum of Years 1-5}, Row2, Row3...Row7 are exactly the same.  I want to calculate the sum of each column in the footer row but I keep getting script errors.

    I am new to LiveCycle.  I need to sum a column in a fixed table.  My rows are summing correctly.  I have tried every formula on the web both in FormCalc and Javascript.  I've cut and pasted script from Adobe templates and from forms on the web.  Nothing is working.  Each change produces a new set of errors.  The Hierarchy is:  (untitled Subform) (page 2), Table 2, Header Row {Header Row contains Year 1, Year 2...Year 5}, Row1 {Row1 contains Text Title, Cell2, Cell3, Cell4, Cell5, Cell6, (untitled Numeric Field) which is a calculated sum of Years 1-5}, Row2, Row3...Row7 are exactly the same.  I want to calculate the sum of each column in the footer row but I keep getting script errors.

  • How do you sum columns in same view

    I have a search component (drag and drop the viewCriteria) with a table.
    In the table is a column for an amount (number). I need to sum the amount and put it in the footer.
    I have done this many times with master/detail. Lots of info on that on the web as well. Really simple.
    In the view:
    So I create a transient attribute (sumAmount).
    I set the value to Expression and use one of the following (and several others that are not here).
    On the screen:
    drag SumAmount from the DC onto the footer. (OutputText no label)
    OK so far!?
    Run and query - (wishful thinking)
    Change the query and new totals appear (not that far yet).
    I have tried several permutations.
    adf.object.sum("Amount")
    sum("Amount")
    adf.object.ViewVO.getrowset.sum("Amount")
    All show absolutely nothing - I have the output text defined in the footer and the footer is displaying fine.
    The table also has some dates in the criteria - when I generate the rowImpl - the search panel is rendered useless due to the Date Domain vs Sql Date ( I know how to manage this)
    This has to be simple - just need to get a bit of help on it.
    I have tried to do this similar to the master/detail (but in this case - no detail). Still no value.
    I should be able to create a "formula" column without the use of java rowImpl.

    Finally - I have all the pieces - they are (were) as follows.
    1) create the View Object.
    2) add the summary column (transient) (be sure to get the data type correct (Number or BigDecimal)).
    3) create the view object implementation. (the Java tab in the view object - first box)
    4) create the view row implementation and expose the accessors. (the Java tab in the view object - second box).
    5) use Steve Muench's help to do the summation - it is a bit tricky and it has a depreciated call in it - but it works. (it is easy to modify to fit - just get the right attribute name for the sum & data type - I used Big Decimal)
    http://otn.oracle.com/products/jdev/tips/muench/recalctotalvo/RecalcTotalOfRowsInVO.zip (may have to look for the proper link - I found a lot of broken references)
    6) add a footer to the table in the search page and drag and output text box into it (all one step with drag and drop) - leave it empty.
    7) in the bindings page of the screen - add an attribute binding for the summary column from the Application Module.
    8) once the binding is made, go back to the output text box and use the inspector to create an expression and bind the value to "adf bindings" - data - and select the view-backing definition from the binding you just created.
    9) if you want to format this to right justified - surround with JSF HTML "panel grid - 1 column width=100% and style= text:align right - I usually do bold as well.
    10) sit back, relax and run - it should work.

  • Help with SUM function ??

    Hi,
    I am trying to build a SUM function into the following SELECT statement;
    SELECT   emp_code "EmployeeCode", trn_date "TransactionDate", project "ProjectCode",
    phase_code "PhaseCode", task_code "TaskCode", reg_hrs "RegularHoursAmt", rate_reg "RegularHoursRate", ot_hrs "OvertimeHoursAmt", rate_ot "OvertimeHoursRate"
    Currently when i do the extract to xls I manually compile the "RegularHoursAmt" and "RegularHoursRate" manually and it's quite a task. I'm sure it can be completed in teh SELECT but I'm not clear on how and it's been quite some time since my last foray into SQL. Any assistance appreciated.
    I need to sum "RegularHoursAmt" and "RegularHoursRate"
    per "EmployeeCode"
    by "TransactionDate"
    with unique combo of "ProjectCode", "PhaseCode", "TaskCode"
    Cheers, Peter

    Hi, Peter,
    PJS5 wrote:
    Thanks Frank for the quick response. Ok, here goes;
    The TABLES already exist and I am only pulling the data for the columns in my SELECT statement so no CREATE of INSERT as such.Post CREATE TABLE and INSERT statements so that the people who want to help you can re-create the problem and test their ideas.
    The data is in Oracle 10g 10.1.0.2.0Perfect!
    So you want totals that represent the entire day for a given employee.
    Yes, but rows are by the unique combo per employee of "ProjectCode", "PhaseCode", "TaskCode"So a row of output will represent a distinct combination of employee, day, ProjectCode, PhaseCode and TaskCode, and that one output row may correspond to more than one row of input; is that right?
    eg Tom works on 4 unique "ProjectCode/PhaseCode/TaskCode" efforts on "TransactionDate"What does "effort" mean here? If I could look at some actaul data (or actual fake data; don't post anything like real credit card numbers) and the results you want from that data, perhaps it would be clear.
    One of those unique "ProjectCode/PhaseCode/TaskCode" efforts however has 3 timesheet entries as he has added unique Descriptions of what his efforts were aimed at achieving.
    We are not extracting the Descriptions and thereby want to SUM those 3 timesheet entries into one row.
    Do you also want a total for each employee, over all days? No thanks
    Do you want a grand total for all employees and all days? No thanks
    Do you want the totals on the same output rows as your current reuslts? That would be handy
    If so, use the analytic SUM function. I'm not familiar with this
    Do you want separate rows for the the totals? That could helpPost the exact results you want from a small set of given data. It's fine to describe the results, as you did above, but describe them in addition to (not instead of) actually showing them.
    Does that make my questions easier to follow?It looks good, but without some sample data and the results you want from that data, I can't say for sure.
    Please post CREATE TABLE and INSERT statements (relevant columns only) for a little sample data, so that I (and the others who want to help you) can see exactly what your tables are like, and actually try our solutions. Simplify as much as possible. For example, if the data is actually coming from a multi-table join, but you already know how to join all the tables perfectly, then pretend all the data is in one table, and post CREATE TABLE and INSERT statements for that one table that looks sort of like your current result set. Post just enough data to show what you want to do. Based on what you've said so far, I'm guessing that 10 to 20 rows of raw data, resulting in 3 to 7 rows of output could give a nice example.
    Also, post the exact results you want from the sample data you post. Explain, with specific examples, how you get those results from that data.
    If parts of your desired output are optional (that is, if some parts "would be handy" or "could help") then post a couple of different sets of results from the same data, and explain, something like this:
    "What I'd really love to get for results is" ...
    but, if that makes things really complicated or inefficient, I don't absolutely need ... or ...,
    so I'd settle for these results: ..."
    I know it's a lot of work to post all this information, but it's really necessary. If I could help you without making you do all this, then I would. Unfortunately, I really don't have a good idea of where you're coming from or where you want to go.
    Edited by: Frank Kulash on Oct 19, 2010 8:01 PM

  • Sum Columns in a jTable?

    (Wasn't completely sure where to post this... but jTable is Swing, right?)
    I have a jTable displaying a database table containing integers corresponding to seats booked. I want to sum these integers in a final column.
    However, the table also contains Primary and Foreign key columns which are also integers. I don't want to sum these, obviously.
    Like this:
    PKey FKey1 FKey2    Col1  Col2  Col3  Col4  Total
    1    2     3        1     0     2     1     4
    2    3     3        1     1     2     2     6
    3    6     8        1     3     1     1     6However, I really haven't been doing this very long, and have no idea where/how to sum these values. Do I write some kind of renderer? Can I do some kind of "int Total = Col1+Col2... etc;"? Or do I sum the values on a lower level and then display the result in the table? In other words: "Help! I'm lost!"

    Well you would probably calculate the total as you first populate the TableModel.
    Then if you data changes dynamciallly you would use a TableModelListener to recalculate the total. Here is a simple example:
    [http://forums.sun.com/thread.jspa?forumID=57&threadID=566133]

  • Help with summing rows

    I really need some help! I have a form has a lot of rows and columns. I know how to sum them using Formcalc, but it would be tedious and time-consuming to do it again and again for all my fields.
    So, here's kind of how the form looks like:
                                                 January           February       March              .......       Total Year
    Recyclable Amount
    Waste Amount
                                                                                    Total Tons
    What I was doing was something like this: Sum(January[0], February[0]....December[0]) under "Total Year". But I would have to repeat this about 20 times for different rows. Is there a script to easily sum across the row, so I don't have to manually change the numbers in the bracket each row? Thanks! I know this might sound confusing, so let me know if my question isn't clear... Thanks in advance!!

    I really need some help! I have a form has a lot of rows and columns. I know how to sum them using Formcalc, but it would be tedious and time-consuming to do it again and again for all my fields.
    So, here's kind of how the form looks like:
                                                 January           February       March              .......       Total Year
    Recyclable Amount
    Waste Amount
                                                                                    Total Tons
    What I was doing was something like this: Sum(January[0], February[0]....December[0]) under "Total Year". But I would have to repeat this about 20 times for different rows. Is there a script to easily sum across the row, so I don't have to manually change the numbers in the bracket each row? Thanks! I know this might sound confusing, so let me know if my question isn't clear... Thanks in advance!!

  • Auto sum Column accumulated value in gridview

    The principle seems simple but I'm in trouble. Did anyone have an example or script to auto sum of a column in the gridview. Explain, I have a gridview with the columns:
    amount, unitary value, total value and accumulated value. I need the accumulated value column add the previous value
    to the current value. For example:
    quantity unitary_value total_value accumulated_value
    10 10,00 100,00 100,00
    20 50,00 1.000,00 1.100,00
    5 500,00 2.500,00 3.600,00
    Basically it would be up. The column value (accumulated value) takes the value of the previous line and adds to the current value.
    If you can help !!
    Thank you for your attention.
    Thank you for your attention.

    No you're right with the calculation of the first post, I got it wrong. Now check the below solution, you need to use RowDataBound event of the gridview to do the calculation and print in the cell:
    //This is just a method to fill the datatable with dummy data(you can ignore in your code)static DataTable GetTable()
    // Here we create a DataTable with four columns.
    DataTable table = new DataTable();
    table.Columns.Add("quantity", typeof(double));
    table.Columns.Add("unitary_value", typeof(double));
    table.Columns.Add("total_value", typeof(double));
    table.Columns.Add("accumulated_value", typeof(double));
    // Here we add five DataRows.
    table.Rows.Add(10, 10, 0, 0);
    table.Rows.Add(20, 50, 0, 0);
    table.Rows.Add(30, 40, 0, 0);
    return table;
    protected void Page_Load(object sender, EventArgs e)
    //Bind the gridview to the datatable
    GridView1.DataSource = GetTable();
    GridView1.DataBind();
    //Global var to keep accumulated value of each rowo
    double _accumulatedvalue = 0;
    protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
    if (e.Row.RowType == DataControlRowType.DataRow)
    //Create total value column by multiplying cells 1 and 2(maybe you don't need this)
    Double val = Convert.ToDouble(e.Row.Cells[0].Text) * Convert.ToDouble(e.Row.Cells[1].Text);
    e.Row.Cells[2].Text = val.ToString();
    //Accumualated value and fill the cell related (you can replace val below with Convert.ToDouble(e.Row.Cells[2].Text)
    _accumulatedvalue = _accumulatedvalue + val;
    e.Row.Cells[3].Text = _accumulatedvalue.ToString();
    Fouad Roumieh

  • Summing column values in sortable dataset

    http://cccw.ecologik.net/admin/lookup/
    Simple page that has a reapting region that is sortable. You notice at the bottom of the table I have a "Total Saved." I would like this to be able to sum up the pSaved column. I know I could get this dynamically when I first create the table in php but once the user sorts, how can I recount the pSaved column? I would think this is a common request but can't seem to find anything about it out there!
    Thanks for any help in advance.
    Jon

    Thanks for the response. After a bit of digging I came up with a solution myself.
    I simply added decided to sum the fields as they went through the filterFunc()
    if (!document.getElementById("containsCB").checked)
        regExpStr = "^" + regExpStr;
        sumOfFields=0
        var regExp = new RegExp(regExpStr, "i");
        var filterFunc = function(ds, row, rowNumber){
           var columnNames = ["Last","First","email","watershed","pledge","City"],
           result = false;
             for( var i = 0; i < columnNames.length; i++ ){
                        // search for a match
                   if( row[ columnNames[i] ] && row[ columnNames[i] ].search( regExp ) != - 1 ){
                        result = true;
                        sumOfFields=sumOfFields + Number(row["pSaved"])
                        break; // stop looping.
    on the table page itself I added small piece of code.
    <script type="text/javascript">
              document.getElementById("resultsArea").innerHTML=sumOfFields;
    </script>
    Works like a charm! Thanks again for the input!

Maybe you are looking for

  • Lock ups and general lag

    Hi guys, Has anyone had any issue with the phone locking up/freezing on them? Its happened to me the last couple of nights now... I've been browsing the menus and it just slows down and becomes unresponsive and laggy. Barely usable! I have to shut do

  • [JS] [CS5] Copy and paste into existing array

    Hi Guys, right now I'm trying to improve the performance of a Script I wrote by copying and pasting a PDF instead of loading it 10 times. And here's the problem: When pasting the copied PDF it doesn't paste it into the array the original PDF is in bu

  • Reading the form as XML, using WDJ

    Hello. I'm using WD for Java and ZCI layout. I've seen this thread- Re: Data in dynamic table not pass to webdynpro java about getting data from tables in the form by reading the form's XML data. I tried to search for a method to get the XML in IWDIn

  • Writing to disk with Oracle...

    Hi, does Oracle use the operating system input/output system calls in order to write/read from/to disk, or does it use its own routines. Does it use the caching mechanisms of UNIX-like systems? Since Oracle has its own caching mechanisms for writing

  • Lightroom→Photoshop CC 2014への連携ができない

    Adobe Creative Cloud アップデート(2014-06-19)を行うと.Lightroom→Photoshop連携ができなくなった. ▼詳細 Lightroomで他のツールで編集→Adobe Photoshop CC 2014で編集を選択 自動でPhotoshop CC 2014が起動 (本当ならここで写真がPhotoshopに読み込まれるが.単純にPhotoshopが起動するだけ) ▼バージョン情報 Adobe Photoshop Lightroom 5.5 (CameraRa