select
tb1.county,
tb1.township,
sum(tb2.periodCumulativeIncome) as periodCumulativeIncome,
sum(tb2.otherIncome) as otherIncome,
count(case when tb2.periodCumulativeIncome >= 5 then tb2.id end) as fiveUpCount,
count(case when tb2.periodCumulativeIncome >= 10 then tb2.id end) as tenUpCount,
count(case when tb2.periodCumulativeIncome >= 20 then tb2.id end) as twentyUpCount,
count(case when tb2.periodCumulativeIncome >= 50 then tb2.id end) as fiftyUpCount,
count(case when tb2.periodCumulativeIncome >= 100 then tb2.id end) as millionUpCount,
sum(case when tb2.isOutProverty = 1 then periodCumulativeIncome end) as nopoorAverageVillageSum,
count(case when tb2.isOutProverty = 1 and tb2.periodCumulativeIncome >= 5 then tb2.id end) as nopoorFiveUpCount,
count(case when tb2.isOutProverty = 1 and tb2.periodCumulativeIncome >= 10 then tb2.id end) as nopoorTenUpCount,
count(case when tb2.isOutProverty = 1 and tb2.periodCumulativeIncome >= 20 then tb2.id end) as nopoorTwentyUpCount,
count(case when tb2.isOutProverty = 1 and tb2.periodCumulativeIncome >= 50 then tb2.id end) as nopoorFiftyUpCount,
count(case when tb2.isOutProverty = 1 and tb2.periodCumulativeIncome >= 100 then tb2.id end) as nopoorMillionUpCount
from
tb1 left join tb2 on tb1.id = tb2.id
group by
tb1.county,tb1.township
mysql分组统计的一种写法
最新推荐文章于 2024-05-16 14:56:10 发布