sql - how to sum a column from one table and group the sum using data from column of another table -


i having problem trying sum column of 1 table , group according data table. common key have account number.

here scenario

table 1.  account_no  volume  read_date 1            32      12016 2            22      12016 3            20      12016 4            21      12016 5            54      12016 3            65      12016 7            84      12016 8            21      12016 9            20      12016 10           30      12016 

=========================================================

table 2  account_no  zone 1            2            3            b 4            b 5            3            7            b 8            b 9            c 10           c 

result

zone total     173 b     146 c     50 

so far how query goes

select sum(volume) total, read_date bdate  group bdate  order bdate 

it able sum volumes based on read_date appreciated...

try this, sum based on read_dates , zones

select a.read_date     ,b.zone     ,sum(a.volume) sumofvolume @table1 inner join @table2 b on a.account_no = b.account_no group a.read_date     ,b.zone 

Comments

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

python - pip wont install .WHL files -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -