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.
groupby の結果を列名として取得する方法
使用時にスタッフテーブルがある場合
性別によるスタッフグループから count(*) を選択します。私に与える
しかし、私は列としてそれらが必要です 女性 | 女性 | なし
select sum(case when gender = 'Male' then 1 else 0 end) as 'Male', sum(case when gender = 'Female' then 1 else 0 end) as 'Female', sum(case when gender not in ('Male','Female') or gender is null then 1 else 0 end) as 'None' from staff;