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.
我的表如下
一个 | b --|-- 0 | 5 1 | 6 2 | 7 3 | 7 4 | 7
我想对组(a = 0,a = 1,a >= 2)求和'b'。
样本输出应该是这样的,
总和 | 一种 ----|--- 5 | 0 6 | 1 21 | 2
我应该使用什么查询?
那应该这样做:
SELECT CASE WHEN a = 0 THEN '0' WHEN a = 1 THEN '1' WHEN a >= 2 THEN '2' END AS anotherNameThanA, SUM(b) AS `sum` FROM yourTable GROUP BY anotherNameThanA