Reputation: 13
Existing Query
SELECT nmindar,
count(indx) FILTER(WHERE indx='Allotted') Allotted,
count(indx) FILTER(WHERE indx='Vacant') Vacant,
count(indx) FILTER(WHERE indx='Amenities') Amenities
FROM plotboundary where indzone='Belagavi Zone' group by nmindar order by nmindar
I want to get the Total of Allotted, Vacant and Amenities.
Upvotes: 0
Views: 50
Reputation: 57381
SELECT nmindar,
count(indx) FILTER(WHERE indx='Allotted') Allotted,
count(indx) FILTER(WHERE indx='Vacant') Vacant,
count(indx) FILTER(WHERE indx='Amenities') Amenities
FROM plotboundary
where indzone='Belagavi Zone'
group by nmindar
UNION ALL
SELECT 'ZZZZZZZZZZZ' as nmindar,
SUM(Allotted) as Allotted,
SUM(Vacant) as Vacant,
SUM(Amenities) as Amenities
FROM (the original query) sub
order by nmindar
Upvotes: 1