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
グループの 'b' を合計したい (a = 0、a = 1、a >= 2)。
サンプル出力は次のようになります。
合計 | a --|--- 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