sql - How do I return the sum for this query? -
i have following tables need find out sum.
table a
id name 1 jason 2 peter 3 ravi
table b
id id_sec 1 11 1 12 1 13 2 21 2 22 2 23 3 31 3 32 3 33
table c
id_sec value include_ind 11 100 y 12 200 y 13 300 n 21 10 y 22 20 n 23 30 n 31 1000 n 32 2000 n 33 3000 n
output
id name total include_ind_count [only count when y] 1 jason 600 2 2 peter 60 1 3 ravi 6000 0
use:
select a.id, a.name, sum(c.value) total table_a join table_b b on b.id = a.id join table_c c on c.id_sec = b.id_sec group a.id, a.name
Comments
Post a Comment