Question of the SUM

Hi gurus

This might be a simple question.
my_table1 - use of zero to represent zeros 
my_column 
5 
2 
0 
3 

my_table2 - use of null to represent zeros 
my_column 
5 
2 
null 
3 
When SUM (my_column) is used, is there a difference in efficiency?

Thank you

All ranks will be visited during the aggregation function. If it can contain null or 0. It does not matter. below test run might answer your question.

PRAZY@11gR2> create table my_table1 as select level my_column from dual connect by level<=4;

Table created.

Elapsed: 00:00:01.11
PRAZY@11gR2> create table my_table2 as select level my_column from dual connect by level<=4;

Table created.

Elapsed: 00:00:00.05
PRAZY@11gR2> update my_table1 set my_column=0 where my_column=3;

1 row updated.

Elapsed: 00:00:00.11
PRAZY@11gR2> update my_table2 set my_column=null where my_column=3;

1 row updated.

Elapsed: 00:00:00.04
PRAZY@11gR2> select * from my_table1;

 MY_COLUMN
----------
         1
         2
         0
         4

Elapsed: 00:00:00.00
PRAZY@11gR2> select * from my_table2;

 MY_COLUMN
----------
         1
         2

         4

Elapsed: 00:00:00.00
PRAZY@11gR2> set autotrace on explain
PRAZY@11gR2> select sum(my_column) from my_table1;

SUM(MY_COLUMN)
--------------
             7

Elapsed: 00:00:00.01

Execution Plan
----------------------------------------------------------
Plan hash value: 3234796976

--------------------------------------------------------------------------------
| Id  | Operation          | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |           |     1 |    13 |     3   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE    |           |     1 |    13 |            |          |
|   2 |   TABLE ACCESS FULL| MY_TABLE1 |     4 |    52 |     3   (0)| 00:00:01 |
--------------------------------------------------------------------------------

Note
-----
   - dynamic sampling used for this statement (level=2)

PRAZY@11gR2> select sum(my_column) from my_table2;

SUM(MY_COLUMN)
--------------
             7

Elapsed: 00:00:00.02

Execution Plan
----------------------------------------------------------
Plan hash value: 3416782976

--------------------------------------------------------------------------------
| Id  | Operation          | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
--------------------------------------------------------------------------------
|   0 | SELECT STATEMENT   |           |     1 |    13 |     3   (0)| 00:00:01 |
|   1 |  SORT AGGREGATE    |           |     1 |    13 |            |          |
|   2 |   TABLE ACCESS FULL| MY_TABLE2 |     4 |    52 |     3   (0)| 00:00:01 |
--------------------------------------------------------------------------------

Note
-----
   - dynamic sampling used for this statement (level=2)

PRAZY@11gR2>

That being said, you have an option that ignores null values when using the analytical functions, or you can filter nulls using where clause. Otherwise it will be treated.

HTH,
Prazy

Published by: Prazy on June 28, 2010 16:11

Tags: Database

Similar Questions

  • Question about the SUM of numeric fields

    Hey all,.

    I hope I posted this in the appropriate forum (this could probably go in the forum of the JS as well and if so, please excuse me.)

    My question:

    I have a mileage monthly log with a field where the user enters the odometer of the vehicle beginning reading (this is a MANDATORY FIELD) at the beginning of the month, OR when the vehicle is used first.

    I have then 31 fields below corresponding to the days in a month with each field containing the odometer of END of reading for that day. If the vehicle has not been used for a particular day, the day field would be empty. At the bottom would be a field "total miles". For example, the data must be like this:

    Beginning mileage: 111 111

    1st 111 200

    2nd 111 300

    3rd

    4 112 000

    5 112 300

    6th

    7 113 000

    ...

    ...

    ...

    31 114 100

    MILEAGE TOTAL 2 989

    'Total mileage' = 'Start mileage' LESS ' reading of the odometer of the 31st day AKA the LAST ENTRY for MONTHS.

    That is my question. How can I make the "mileage" field be dynamic? Say that the vehicle was used from the 5th through the 10th, how can I have the "mileage" field display the odometer reading?

    If all goes well, I explained this well enough for someone to help me and any help will be greatly appreciated.

    Hello

    It is an example where FormCalc has an advantage over JavaScript. There are built in functions in FormCalc for maximum and minimum values.

    In the total mileage, you could set up two variables, one for Max and the other for minutes and then subtract.

    var maxMiles = Max(mileage[*])
    var minMiles = Min(mileage[*])
    
    $ = maxMiles - minMiles
    

    This is based on the script to calculate the total field event. It depends also how you have configured the table. If the lines have the same name: for example Row1 [0], Row1 [1], Row1 [2],... Row1 [30] and the mileage field is named the same in each line, then the script may look like:

    var maxMiles = Max(Row1[*].mileage[*])
    

    Hope that helps,

    Niall

    Ensure the dynamics

  • See the sum of subset question quiz on a blade of results

    I want to show the sum of part only of scores question quiz on a blade of results.

    I want to still follow and record the scores of questions (acting as a series of tests), but show that the score some of these question marks (final quiz) to the user. I read these steps http://blog.lilybiri.com/intermediate-score-slides but I only need a subset. I'm not getting any summing the scores showing the partition on the slide.

    Any suggestions welcome... Michelle

    Even if you need only a subset, the workflow is quite similar. I would create a variable used to store the total score for the questions in this subset. After each question to consider, you add the value of the variable cpQuizInfoLastSlidePointsscored of system to the user variable. At the end of these questions (don't forget the last of them), you will have the total score for this subset in this user variable.

  • Somewhere is the sum of control or digital sign for firefox windows install?

    Hello
    Somewhere is the sum of control or digital sign for firefox windows install?

    Latest version of Firefox on the CDN server:

  • Re: A few questions about the Satellite P200 - 1FC

    Hi people,

    died on my trusty laptop and I need a new. The P200 - 1FC seems to do the trick, and I have a few questions that I hope this is the right place for.
    Is there a hardware switch (or key combination) to disable the touchpad? Y at - it an indicator of the State of the touchpad?
    Is there a hardware switch to inactivate the wireless network components?
    Is it possible to add physical memory to the dedicated graphics card?

    I know you can Filch system memory to increase the available for graphics operations, but is it more logical to add system memory or add graphics memory.

    What is the equipment for the memory locations system config factory base with 2 GB of RAM? There are 4 slots or 2? Are they all filled?

    How is it difficult to "downgrade" to XP machine? Will there be XP drivers available for all components?

    Thanks in advance for any help.

    Hello

    I m P200 not owner, but I'll try to answer your questions.

    > Is there a hardware switch (or key combination) to disable the touchpad?
    Yes, the FN + F9 key combination should enable and disable the touchpad!

    > Is it an indicator of the State of the touchpad?
    Well, in the taskbar you should get a notification icon if the touchpad has been disabled

    > Is there a hardware switch to inactivate the wireless network components?
    Yes, the WLan switch is available on laptop computers (probably on the front).

    > Is it possible to add physical memory to the dedicated graphics card?
    No, the graphics card supports an its own local cache. Graphics cards support also hyper memory. This memory hyper depends on the amount of main memory. Total video memory is the sum of the local cache and Hyper memory.
    But once again; physical memory cannot be added.

    > What is the load out for the locations of system memory in config factory base with 2 GB of RAM? There are 4 slots or 2? Are they all filled?
    There are 2 slots of memory and the laptop has been delivered with 2x1024Mo modules.
    The laptop supports 4 GB max memory, but as much as I know Windows 32 bit does recognize only 3.02 GB due to the limitation of the 32 bit OS!

    > How is it hard to "downgrade" to XP machine? Will there be XP drivers available for all components?
    It of not difficult to downgrade the laptop to the XP operating system.
    On the Toshiba site
    http://EU.computers.Toshiba-Europe.com/cgi-bin/ToshibaCSG/download_drivers_bios.jsp?service=EU
    You should find all the drivers for the P200 PSPB6 XP

  • Question about the reports and data of rollups

    We followed in place that I need to create monthly reports. There is a custom agent that collects two key all measures that can be used to define a percentage of system availability. They check essentially two types of errors that may occur together or individually. I have not really used reports in Foglight but has spent a good amount of time to play with them today. The main problem/issue I have at this point is how to deal with the accumulation of data. Our retention policy performs three stacks of separate data in a month, how can you effectively report on these data rolled upward?

    Example: one of the agents simply return a 0 if the system is ok and 1 if it finds the error. In the end, we just need to know how many times that 1 has been returned in a month. How would one accomplish? If the sum is for example, 40 for a total of 4 hours is that it means that he met the 40 times error? The frequency of the agent is set to 60 seconds, so that would mean 40 minutes of time error...?

    The other control agent returns specific error codes and not a simple binary value. If the above example or the question is trivial I still don't know how to deal with this one...

    Most likely, you can use the value of the sum for the metric, just as you might have guessed.  Because the value is 0 or 1, the amount will be the total of the values for the time period.  There are also a number of samples, which should / could be higher because there might be 0.

  • How to calculate the sum of the fields to fill?

    Hello!

    My question is how can I calculate the sum of filled areas?

    For example, in a PDF document, I have a few fields that must be filled out with name and surname and the end of the document, another field that is the sum of the fields "FullName" which shows how many people is in this document. The operation should not take into account white/empty areas.

    Now, I know that I could do with the simple calculation "(+) sum" but I have to put a '1' for each of this area and I would like to avoid this.

    Yes, it's the first option I described. In this case, you can use this code:

    var total = 0;
    for (var i=1; i<=79; i++) {
        if (this.getField("Nume si prenume "+i).valueAsString!="") total++;
    }
    event.value = total;
    
  • The Master Table column updated based on the sum of column Table detail


    With the help of JDev 11.1.1.6.

    I have a master-detail table based on a link to BC.

    The main table has a column that displays an InputText or an OutputText, based on the value in another column.

    If the InputText is displayed, the user can enter a value and the database will be updated with that value.

    If the OutputText is displayed, it must be a sum of a column in the secondary table.  Also, this value will be written in the database.

    Question:

    How can I fill the OutputText in the main table with the sum of the values in a column in the secondary table?

    The detail table column is a manually entered InputText field.

    Thank you.

    Create a spike in the main table and write in its expression as follows - DetailVoAccessorName.sum ("ColumnName");

    This will calculate the sum of column table detail and then you can set the value of the transient attribute to attribute DB on backup operation

    Ashish

  • Helps with the sum on partition

    Hi all

    This is my sample data:

    create table general(
    general_id number,
    general_type nvarchar2(10),
    start_year number,
    end_year number,
    fy number,
    fy_value number
    );
    
    insert into general(general_id, general_type, start_year, end_year, fy, fy_value)
    values (1, 'data 1', 2009, 2013, 2010, 10);
    insert into general(general_id, general_type, start_year, end_year, fy, fy_value)
    values (1, 'data 1', 2009, 2013, 2013, 20);
    insert into general(general_id, general_type, start_year, end_year, fy, fy_value)
    values (2, 'data 2', 2010, 2014, 2010, 5);
    insert into general(general_id, general_type, start_year, end_year, fy, fy_value)
    values (2, 'data 2', 2010, 2014, 2013, 15);
    
    SELECT general_id, general_type, fy,
      sum(fy_value) over (partition by general_id, general_type order by fy) sum_fy_value
    FROM general
    

    My results:

    
    GENERAL_ID    GENERAL_TYPE    FY    SUM_FY_VALUE
    1    data 1    2010    10
    1    data 1    2013    30
    2    data 2    2010    5
    2    data 2    2013    20
    

    How can I complete the sum of the missing years (with leading zeros), from my year start and end?

    Example of final results:

    GENERAL_ID    GENERAL_TYPE    FY    SUM_FY_VALUE
    1    data 1    2009    0
    1    data 1    2010    10
    1    data 1    2011    10
    1    data 1    2012    10
    1    data 1    2013    30
    2    data 2    2010    5
    2    data 2    2011    5
    2    data 2    2012    5
    2    data 2    2013    20
    2    data 2    2014    20
    

    Oracle Database 11g - 11.2.0.4.0

    Thanks in advance.

    SQL> with t
      2  as
      3  (
      4   select general_id
      5        , general_type
      6        , start_year + (level-1) fy
      7     from (
      8            select distinct general_id
      9                 , general_type
     10                 , start_year
     11                 , end_year
     12              from general
     13          )
     14  connect
     15       by level <= end_year - start_year + 1
     16      and prior general_id = general_id
     17      and prior dbms_random.value is not null
     18  )
     19  select t.general_id
     20       , t.general_type
     21       , t.fy
     22       , sum(nvl(g.fy_value, 0)) over(partition by t.general_id order by t.fy) sum_fy_value
     23    from t
     24    left join
     25         general g
     26      on t.general_id = g.general_id
     27     and t.fy         = g.fy
     28   order
     29      by general_id
     30       , fy;
    
    GENERAL_ID GENERAL_TY         FY SUM_FY_VALUE
    ---------- ---------- ---------- ------------
             1 data 1           2009            0
             1 data 1           2010           10
             1 data 1           2011           10
             1 data 1           2012           10
             1 data 1           2013           30
             2 data 2           2010            5
             2 data 2           2011            5
             2 data 2           2012            5
             2 data 2           2013           20
             2 data 2           2014           20
    
    10 rows selected.
    

    Note: I must say that it is one of these well posed the question, which we do not often here. I appreciate you providing sample data and expected outcomes in a well-formatted way and also provides the oracle version 4-digit.

  • Display the sum of all salaries of employees @ footer section

    Hi team,

    I use Jdev 11.1.2.3.0 version.

    I have a requirement where I need to see the sum of all the wages of employees in the employee table footer section in the user interface.

    Is there a declarative approach to this question without using any method Java and master-details relationship.

    Let me know if you need additional information on my problem.

    Thanks in advance,

    Check out ADF - Groovy amounting to Total of a column in a Table. Techartifact that should make your use case.

    Timo

  • Columns of the sum of different record count of joined tables

    I have a problem with a query, please help.

    I have two tables:
    create table rec_a (key_code varchar(20),
                    TOT_AMT varchar(20),
                    INV_AMT varchar(20))
    / 
     
    create table rec_B (key_code varchar(20),
                    INVOICE_AMT varchar(20),
                   PAID_AMT varchar(20))
    / 
     
    insert into REC_A values (123123,  1168182.16, 1168182.16);
    
    insert into REC_B values (123123, 205699.04,205699.04);
    insert into REC_B values (123123,130912.78,130912.78);
    insert into REC_B values (123123, 81622.87,81622.87);
    insert into REC_B values (123123, 438032.43,438032.43);
    insert into REC_B values (123123, 159936.17,159936.17);
    insert into REC_B values (123123, 151978.87,151978.87);
     
    Table 1
    KEY_CODE TOT_AMT INV_AMT
    123123 1168182.16 1168182.16


    Table 2
    KEY_CODE INVOICE_AMT PAID_AMT
    123123 205699,04 205699.04
    123123 130912,78 130912.78
    123123 81622,87 81622.87
    123123 438032,43 438032.43
    123123 159936,17 159936.17
    123123 151978,87 151978.87


    I wrote a query to sum up all the areas (tot_amt, inv_amt, invoice_Amt, paid_amt)
    SELECT B.key_code,sum(A.invoice_amt),sum(a.paid_amt),SUM(b.tot_Amt),SUM(b.inv_amt) FROM rec_a B, rec_b A WHERE A.KEY_CODE=B.KEY_CODE AND B.KEY_CODE in ('123123')
    group by B.key_code
    I got this:

    KEY_CODE SUM (A.INVOICE_AMT) SUM (A.PAID_AMT) SUM (B.TOT_AMT) SUM (B.INV_AMT)
    123123 1168182.16 1168182.16 7009092.96 7009092.96

    But I expected this

    KEY_CODE SUM (A.INVOICE_AMT) SUM (A.PAID_AMT) SUM (B.TOT_AMT) SUM (B.INV_AMT)
    123123 1168182.16 1168182.16 1168182.16 1168182.16


    Can someone help me out here?

    Thank you

    Published by: 1003064 on April 29, 2013 03:19

    Hello

    1003064 wrote:
    I have a problem with a query, please help.

    I have two tables:
    Table 1
    KEY_CODE TOT_AMT INV_AMT
    123123 1168182.16 1168182.16

    Table 2
    KEY_CODE INVOICE_AMT PAID_AMT
    123123 205699,04 205699.04
    123123 130912,78 130912.78...
    123123 81622,87 81622.87
    123123 438032,43 438032.43
    123123 159936,17 159936.17
    123123 151978,87 151978.87

    I wrote a query to sum up all the areas (tot_amt, inv_amt, invoice_Amt, paid_amt)

    SELECT B.key_code, sum (a.invoice_amt), sum (a.paid_amt), SUM (b.tot_Amt), SUM (b.inv_amt) FROM rec_a A, rec_b B WHERE A.KEY_CODE = B.KEY_CODE AND B.KEY_CODE in ('123123')
    B.key_code group

    I got this:
    KEY_CODE SUM (A.INVOICE_AMT) SUM (A.PAID_AMT) SUM (B.TOT_AMT) SUM (B.INV_AMT)
    123123 1168182.16 1168182.16 7009092.96 7009092.96

    But I expected this

    KEY_CODE SUM (A.INVOICE_AMT) SUM (A.PAID_AMT) SUM (B.TOT_AMT) SUM (B.INV_AMT)
    123123 1168182.16 1168182.16 1168182.16 1168182.16

    Thus, the last 2 columns must be exactly what is stored in table1? Then either
    b include these columns in the GROUP BY clause and not to use the SUM,
    (b) the GROUP BY on rec_a alone, separately, can't join the results to the rec_b, or
    (c) using MIN or MAX, instead of SUM. (Anyone. Since there is only one value, MIN will be the same as MAX.)

    Here is an example of (a):

    SELECT    B.key_code
    ,       sum (a.invoice_amt)     AS sum_invlice_amt
    ,       sum (a.paid_amt),     AS sum_paid_amt
    ,       b.tot_Amt
    ,       b.inv_amt
    FROM        rec_a          A
    ,        rec_b          B
    WHERE        A.KEY_CODE     = B.KEY_CODE
    AND        B.KEY_CODE      in ('123123')
    group by  B.key_code
    ,            b,tot_amt
    ,       b.inv_amt
    ;
    

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all of the tables involved and the results desired from these data.
    Point where the above query is to produce erroneous results, and explain, using specific examples, how you get the right results from data provided in these places.
    Always say what version of Oracle you are using (for example, 11.2.0.2.0).
    See the FAQ forum {message identifier: = 9360002}

  • What type of input parameter is used according to the SUM?

    Hello world
    As we know sum is an oracle function preset. But what these guys here oracle used for input parameters. How did they do that?
    I mean, we can write this sum fuction as many ways as as mentioned below. Please give me some ideas how to do this.
    SELECT SUM(salary) as "Total Salary" FROM employees;
    
    SELECT SUM(DISTINCT salary) as "Total Salary" FROM employees;
    
    SELECT SUM(income - expenses) as "Net Income" FROM gl_transactions;
    
    SELECT SUM(sales * 0.10) as "Commission" FROM order_details;
    Kind regards
    BS2012

    BS2012 wrote:
    Hello world
    As we know sum is an oracle function preset. But what these guys here oracle used for input parameters. How did they do that?
    I mean, we can write this sum fuction as many ways as as mentioned below. Please give me some ideas how to do this.

    SELECT SUM(salary) as "Total Salary" FROM employees;
    
    SELECT SUM(DISTINCT salary) as "Total Salary" FROM employees;
    
    SELECT SUM(income - expenses) as "Net Income" FROM gl_transactions;
    
    SELECT SUM(sales * 0.10) as "Commission" FROM order_details;
    

    Kind regards
    BS2012

    As others have said, your question is not very clear.

    There are many aspects and angles to look at what you're asking.

    First of all, a level superior, the sum function simply takes a numeric value as it's argument, so all of these examples you gave have expressions that evaluate to a numeric value to be provided to the sum function. (As someone else already mentioned you can have non-numeric data types, just as long as they can be implicitly converted to a numeric value).

    A statement analysis and the point of view of enforcement, the content of the expression inside the brackets is evaluated before being passed to the sum function. It is not the function sum that he himself takes the expression and evaluates it. The sum function is expecting just a single numeric value.

    Internally, what the function sum is the case, is more than just a single... call function and return a value, because it faces several values being passed in the aggregation group. As such, it must have the ability to know if to start in short, is to accept several input values, so he can add them together, you know give up adding entries and pass the result to the back.

    If we write our own defined aggregate function (others have already provided a link to explain this) we can see what is happening internally. In the following example, we'll write a function defined by the user that multiplies the values rather than the amounts...

    create or replace type mul_type as object(
      val number,
      static function ODCIAggregateInitialize(sctx in out mul_type) return number,
      member function ODCIAggregateIterate(self in out mul_type, value in number) return number,
      member function ODCIAggregateTerminate(self in mul_type, returnvalue out number, flags in number) return number,
      member function ODCIAggregateMerge(self in out mul_type, ctx2 in mul_type) return number
      );
    /
    create or replace type body mul_type is
      static function ODCIAggregateInitialize(sctx in out mul_type) return number is
      begin
        sctx := mul_type(null);
        return ODCIConst.Success;
      end;
      member function ODCIAggregateIterate(self in out mul_type, value in number) return number is
      begin
        self.val := nvl(self.val,1) * value;
        return ODCIConst.Success;
      end;
      member function ODCIAggregateTerminate(self in mul_type, returnvalue out number, flags in number) return number is
      begin
        returnValue := self.val;
        return ODCIConst.Success;
      end;
      member function ODCIAggregateMerge(self in out mul_type, ctx2 in mul_type) return number is
      begin
        self.val := self.val * ctx2.val;
        return ODCIConst.Success;
      end;
    end;
    /
    create or replace function mul(input number) return number deterministic parallel_enable aggregate using mul_type;
    /
    

    For example, our user-defined aggregate function is based on a total object type.
    This object keeps a value ("val" in our example).
    It has an Initialize method, so when the SQL engine indicates that this is the beginning of an aggregation of values it can set its value to an initial value (in this case zero).
    It has an Iterate method, the SQL engine passes the values to it in the context of all grouped values, it can treat them (in our case it multiplies the value of entry with the value already there for this game of aggregations (and takes a value of 1 for the first iteration basis))
    She has a Terminate method, so when the SQL engine indicates that the global set of values is completed, it can return the result.
    The last method there is a merger and is mandatory, so that when the aggregation is done parallel assessment tool (for better performance internally), the results of these parallel executed aggregations can be combined (see http://docs.oracle.com/cd/E11882_01/appdev.112/e10765/ext_agg_ref.htm#ADDCI5132). As we are multiplying numbers, in our case, it is simply a case of the multiplication of one single result with each other.

    And to see that it works...

    SQL> with t as (select 2 as x from dual union all
      2             select 3 from dual union all
      3             select 4 from dual union all
      4             select 5 from dual)
      5  --
      6  select mul(x)
      7  from t;
    
        MUL(X)
    ----------
           120
    
  • How to make the sum of hours which is the varchar2 data type in oracle

    Hi my table is like this
    emp_ngtshthrs (empno number (10), nightshifthrs varchar2 (20));

    now I want sum employee nightshifthrs how do the sum hours, it's my hours 01:00, 05:00, 08:00, 10:00, 07:00 and 09:00
    I want the sum type varchar2 hours how to do? and I want to display the sum is greater than 24:00

    Well, first of all you have posted your question in the wrong forum. You should have posted your question in the forum SQL and PL/SQL .

    The second problem I see is that you are being too generic when you have your employees enter their night shift hours worked. If you are able, I recommend that you change your table to record hours separately from minutes and make columns of type NUMBER instead of the VARCHAR2() type. Then, you can simply use arithmatic to total the hours and minutes worked.

    If you are locked in your table and cannot change it, you can convert characters to numbers and then perform your basic arithmatic on values. For example:

      1  with tab1 as (
      2  select 10 as empno, '01:00' as nightshifthrs from dual union all
      3  select 10 as empno, '05:00' as nightshifthrs from dual union all
      4  select 10 as empno, '08:00' as nightshifthrs from dual union all
      5  select 10 as empno, '10:00' as nightshifthrs from dual union all
      6  select 10 as empno, '07:00' as nightshifthrs from dual union all
      7  select 10 as empno, '09:00' as nightshifthrs from dual)
      8  select sum(to_number(replace(nightshifthrs,':','.'))) AS hours_worked
      9* from tab1
    SQL> /
    
    HOURS_WORKED
    ------------
              40
    SQL> 
    

    Of course, if your users can and do enter the minutes, then which complicates the example I provided. You will need to convert the decimal minute, sum the amount, then convert the decimal time and add this to your hours. For example:

      1  with tab1 as (
      2  select 10 as empno, '01:15' as nightshifthrs from dual union all
      3  select 10 as empno, '05:00' as nightshifthrs from dual union all
      4  select 10 as empno, '08:30' as nightshifthrs from dual union all
      5  select 10 as empno, '10:00' as nightshifthrs from dual union all
      6  select 10 as empno, '07:45' as nightshifthrs from dual union all
      7  select 10 as empno, '09:00' as nightshifthrs from dual)
      8  select sum(to_number(substr(nightshifthrs,1,2))) + SUM(to_number(SUBSTR(nightshifthrs,4,5)))/60
      9* from tab1
    SQL> /
    
    HOURS_WORKED
    ------------
            41.5
    SQL> 
    

    I hope this helps.

    Craig...

  • How to get the sum of the first row in the previous row?

    Dear gurus... I need to get the sum of a column of the first row of my result set to the previous line based on a condition. I read analytical functions for this but they provide the sum of the first rank to Current Row through declaration "rows between Unbounded preceding and current line. Y at - it a statement that calculates the sum as "rows between Unbounded preceding and previous row?

    Hello

    kamranpathan wrote:
    Dear gurus... I need to get the sum of a column of the first row of my result set to the previous line based on a condition. I read analytical functions for this but they provide the sum of the first rank to Current Row through declaration "rows between Unbounded preceding and current line.

    If you do not explicitly give a windowing clause, then you get the default windowing clause you indicated.
    If you want another clause of windowing, ionclude in the analytic function call.

    Y at - it a statement that calculates the sum as "rows between Unbounded preceding and previous row?

    Yes. The correct syntax for "Previous rank" is «PREVIOUS 1»

    ...  ROWS BETWEEN  UNBOUNDED PRECEDING
                AND        1          PRECEDING
    

    For more information, search for "Analytic Functions" in the manual of the SQL language:
    http://download.Oracle.com/docs/CD/E11882_01/server.112/e17118/functions004.htm#sthref917

    I hope that answers your question.
    If not, post a small example of data (CREATE TABLE and only relevant columns, INSERT statements) for all tables and also post the results desired from these data.
    Explain, using specific examples, how you get these results from these data.
    Always tell what version of Oracle you are using.
    You will find the answers better faster if you always provide this information whenever you post a question.

    Published by: Frank Kulash, Sep 17, 2011 17:04
    I just saw Etbin responses.
    As usual, Etbin has a good point. If the column that you are basically cannot be NULL, then it is probably easier to subtract the total current line and use the default windowing clause.
    Even if it can be null, you find may be easier to use this approach.

  • Script to automatically calculate answers to the questions of the option button?

    Hello

    Anyone know if its possible / how to write a script to automatically count the responses of the radio buttons?

    For example, I have a form with 14questions, where the answers are either "Yes" 'Unknown' and 'No' - I used for each question radio buttons.

    At the bottom of the form, I want it to be automatically calculate how much 'yes' 'unknown' and 'No' responses there. (ie. a text box that displays the number of 'Yes', another area of text that displays the number of 'No'... etc)

    Can someone help me with this?

    Thank you so much

    OK, for the text field that counts the groups of numbers with the Yes option radio button is selected, you can use code like:

    // Custom Calculate script for text field
    (function () {
    
        // Initialize counter
        var sum = 0;
    
        // Loop through the fields
        // and increment the counter for each Yes value
        for (var i = 1; i < 15; i += 1) {
            if (getField("Question " + i).value === "Yes") {
                sum += 1;
            }
        }
    
        // Set the value of this field to the sum
        event.value = sum;
    
    })();
    

    Do the same for other areas, but change the 'yes' in the code above to the appropriate string, either 'No' or 'Unknown'.

    It would make sense to convert this to a function in a script at the level of the document, something like:

    // Document-level function
    var radioButtonValueCount = function (sVal) {
    
        // Initialize counter
        var sum = 0;
    
        // Loop through the fields
        // and increment the counter for each sVal value
        for (var i = 1; i < 15; i += 1) {
            if (getField("Question " + i).value === sVal) {
                sum += 1;
            }
        }
    
        // Set the value of the field that called this function to the sum
        event.value = sum;
    
    }
    

    You would then call it like that in the case of calculating a text field that counts the number of selections of Yes:

    // Set this field to the number of Yes selections
    radioButtonValueCount("Yes");
    

    Do the same for Dummies and unknown fields.

Maybe you are looking for

  • Satellite L300D WIN XP drivers needed

    Dear all, I have a problem with my laptop Toshiba L300D quite new. My younger brother wanted to install XP instead of Vista.The hard drive has been formatted and installed WIN XP Professional. Now, it has the problem that the laptop is not working pr

  • What is this security shield Virus Scanner Software?

    IT SCANNED MY LAPTOP, THIS SECURITY SHIELD software 2012 antivirus tells me to buy the product and save the activation key and open up my firewall. is this MICROSOFT.can I buy it offline?

  • How can I remove mcci browser?

    How can I get rid of the mcci browser? Don't know how it got here, but it has many addons and windows does not see the .exe program file to remove. I think it is causing IE to run very slowly. Can you help me?

  • Computer to overwrite/freezing during Virus Scan,

    Hello... When I scan my c: with AVG and Windows malware, it freezes/then crashed the computer to "\windows\inf\*", it's always somewhere in the "inf" folder, and not always to the same file.  If I leave the computer in frozen mode, I get the "Blue Sc

  • Parts of blackBerry Smartphones

    Hello New here.  How or where can I do to get part of their BBC?  I lost the control lever for the cover and need a repalcement. Fred