现有查询
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
我希望获得分配,空置和设施的总数。
答案 0 :(得分:1)
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