DBAsupport.com Forums - Powered by vBulletin
Results 1 to 2 of 2

Thread: SQL Query

  1. #1
    Join Date
    Aug 2001
    Posts
    40
    Hi all,
    i have a problem with my query i wanna sum up a value based on a column,
    say my table has data as

    empno date amount
    1 **** 100
    2 **** 250
    2 **** 220
    3 **** 200
    2 **** 200
    2 **** 450
    1 **** 275

    i wanna select th empno,date,amount and also total amount
    group by each employee

    i mean for employee 1 it needs to list all the columns for employee1 and total amount against it
    or else in the total amount column i can have the same values ie for employee 1 it can be

    empno date amount total amount
    1 **** 200 475
    1 **** 275 475

    i need both the rows coz dates may be different

    thanks,

  2. #2
    Join Date
    Apr 2001
    Location
    Czechia
    Posts
    712
    Hi,
    this might be the solution:
    scott@oracle> select * from the_table;

    EMPNO DAT AMOUNT
    ---------- ------------------- ----------
    1 31.08.2001 17:22:02 100
    2 31.08.2001 17:22:19 250
    2 31.08.2001 17:22:32 220
    3 31.08.2001 17:22:50 200
    2 31.08.2001 17:23:01 200
    2 31.08.2001 17:23:15 450
    1 31.08.2001 17:23:25 275

    7 rows selected.

    scott@oracle>
    1 select A.empno, A.dat, A.amount, B.total
    2 from
    3 the_table A,
    4 (select empno, sum(amount) as total from the_table group by empno) B
    5 where A.empno=B.empno
    6* order by empno, amount

    EMPNO DAT AMOUNT TOTAL
    ---------- ------------------- ---------- ----------
    1 31.08.2001 17:22:02 100 375
    1 31.08.2001 17:23:25 275 375
    2 31.08.2001 17:23:01 200 1120
    2 31.08.2001 17:22:32 220 1120
    2 31.08.2001 17:22:19 250 1120
    2 31.08.2001 17:23:15 450 1120
    3 31.08.2001 17:22:50 200 200

    7 rows selected.



    Regards, Ales

Posting Permissions

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


Click Here to Expand Forum to Full Width