Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是我的 SQL:
SELECT DISTINCT(CASE WHEN state=18 THEN lga ELSE 'Others' END) LGA, COUNT(CASE WHEN choice=21 THEN choice END ) NDCH FROM bio GROUP BY lga
我的期望是它给我所有状态 = 18 的 LGA,如果状态不等于 18,则将它们归为“其他”,但我通常有多个“其他”。请帮忙。
考虑一个group by案例陈述:
group by
SELECT CASE WHEN state=18 THEN lga ELSE 'Others' END LGA , COUNT(CASE WHEN choice=21 THEN choice END) NDCH FROM bio GROUP BY CASE WHEN state=18 THEN lga ELSE 'Others' END