these are my tables
C_ID USAGE B_ID
4 100 2
2 400 1
3 200 2
1 300 1
and
B_ID ZONE_NAME
2 central
1 west
and here is my query,
select
sum(usage)
from
(
select
usage_679.c_id,
usage_679.b_id,usage_679.usage,
zone_679.zone_name
from usage_679 inner join zone_679
on zone_679.b_id = usage_679.b_id
)
where zone_name like 'w%';
problem is that it can print data related to west zone only.I want to print both zone name with total usage in respective zone.
expected output
zone_name sum(usage)
1 700
2 300
Here is SQL FILLDE LINK FOR SAMPLE EXECUTION . You don’t need WHERE condition . You can achieve via GROUP BY
OUTPUT
Even this would work: (No need of 2 SELECTS)
OUTPUT: