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.
以下の行を持つテーブルがあります
氏名 月 給与 経費 ジョン 1 月 1000 50 ジョン 2 月 5000 2000 ジャック 1 月 3000 100
ジョン 1 月 1000 50 ジョン 2 月 5000 2000 ジャック 1 月 3000 100
以下の形式で出力したい。これを達成する方法。
名前 JAN FEB ジョン 1000 50 5000 2000 ジャック 3000 100 0 0
ジョン 1000 50 5000 2000 ジャック 3000 100 0 0
この sql(-server) クエリは機能します。
select name, isnull(max(case when month='jan' then salary end), 0) as Salary_jan, isnull(max(case when month='feb' then salary end), 0) as Salary_feb -- and so on group by name