select fund_account,BrokerID,
sum(case when RulesID>1000000 AND RulesID<2000000 then 1 else 0 end ),
sum(case when RulesID>2000000 AND RulesID<3000000 then 1 else 0 end ),
sum(case when RulesID>3000000 AND RulesID<4000000 then 1 else 0 end ),
sum(case when RulesID>4000000 AND RulesID<5000000 then 1 else 0 end )
from investorrules where fund_account like '%1%' GROUP BY fund_account,BrokerID limit 1,21
转载于:https://www.cnblogs.com/a9999/p/7826865.html
本文介绍了一个具体的SQL查询案例,演示了如何使用CASE WHEN语句结合分组函数进行复杂的数据筛选与统计。案例中,通过BrokerID和fund_account对数据进行分组,并根据不同范围的RulesID进行计数,最后对结果进行限制展示。
3286

被折叠的 条评论
为什么被折叠?



