d2294 d2294 - 11 months ago 80
SQL Question

Query 2 sum in 1 table

table a

column id : a a b b
column total : 1 2 1 3

how can i show? in one table without use compute

a 3 7
b 4 7

Answer Source

Do group by to sum each id's total. Do a sub-select to count total:

select id,
       sum(total) as total,
       (select sum(total) from a) as totalall
from a
group by id