Results 1 to 3 of 3

Thread: How to get SUM

  1. #1
    Join Date
    Jan 2012
    Posts
    5

    Unanswered: How to get SUM

    Hi All,
    i have a table and i want count as well as sum together eg below

    Status ----Count
    1 ---- 2
    2 ----- 3
    3 ---- 4
    4 ---- 5
    Total ---- 14
    i want this output how to get it pls help me
    for count i am using this query
    select status,count(*) from table group by status

    pls let me know which query is used to generate above output.

    thanks in advance

  2. #2
    Join Date
    Jan 2004
    Location
    Croatia, Europe
    Posts
    4,094
    Provided Answers: 4
    Here's one (SQL*Plus) option:
    Code:
    SQL> break on report
    SQL> compute sum of cnt on report
    SQL> select deptno, count(*) cnt
      2  from emp
      3  group by deptno
      4  order by deptno;
    
        DEPTNO        CNT
    ---------- ----------
            10          3
            20          5
            30          6
               ----------
    sum                14
    
    SQL>

  3. #3
    Join Date
    Jul 2003
    Posts
    2,296
    analytic functions are great too:
    Code:
    the_duck@dev3> select username, count(*), sum(count(*)) over (order by username) running_total 
    from v$session having count(*) > 5 group by username;
    
    USERNAME                 COUNT(*) RUNNING_TOTAL
    -------------------- ------------ -------------
    ABC_SCHEMA                    114           114
    ABC_USER                       14           128
    ABC_OWNER                      43           171
    OPENFIRE                       11           182
    XYZ                            69           251
    - The_Duck
    you can lead someone to something but they will never learn anything ...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •