sql - How to add up column data values when using GROUP BY -


i working data utility company. have table contains sales records customers. each sales record has customer number, sale date, sales document number, , sales amount. there 1 record each sales document number. sales amount has been computed second table contains daily usage (ccf's) customer during month. 2 tables joined sales document number. need summarize daily usage 1 total. summary should include of columns listed above, plus total usage. here sample of data.

table  customernumber       date        salesdocnumber      amount  15422                06/14/2012    123-utl-23001     $112.25 13784                12/07/2007    854-utl-14096     $75.11 

and

table b  salesdocnumber        ccf 123-utl-23001         25.45 123-utl-23001         118 123-utl-23001         56.10 854-utl-14096         10.65 854-utl-14096         15 854-utl-14096         13 854-utl-14096         22.75 854-utl-14096         31 

this query

select a.customernumber,        a.date,        a.salesdocnumber,        a.amount        b.ccf table inner join table b on a.salesdocnumber = b.salesdocnumber group a.customernumber, a. date, a.salesdocnumber, a. amount, b.ccf 

my results show line each record in table b rather having them summarized 1 line.

expected results are

15422    06/14/2012   123-utl-23001  $112.25  199.55 13784    12/07/2001   854-utl-14096  $75.11   92.40 

any appreciated!!

select a.customernumber,        a.date,        a.salesdocnumber,        a.amount        b.ccf tablea inner join (select salesdocnumber, sum(ccf) ccf tableb group salesdocnumber) b on a.salesdocnumber = b.salesdocnumber 

Comments

Popular posts from this blog

javascript - RequestAnimationFrame not working when exiting fullscreen switching space on Safari -

Python ctypes access violation with const pointer arguments -