0
は、私は次の表のデータを持っている:基本的なピボットテーブル
select person_name, appointment_id, unique_encounter, enounter_code
from appointment
person_name appointment_id unique_encounter enounter_code
----------- -------------- ---------------- -------------
Mike 123 A1 CG
Mike 123 A1 DT
John 458 1F CG
Bill 555 AB AJ
Joe 197 ZZ CG
Joe 197 ZZ AJ
Joe 197 ZZ DT
私は次のような結果を達成するためのクエリを記述しようとしています:
person_name appointment_id unique_encounter enounter_code_1 enounter_code_2 enounter_code_3
----------- -------------- ---------------- ------------- --------------- ---------------
Mike 123 A1 New Deleted
John 458 1F New
Bill 555 AB Updated
Joe 197 ZZ New Updated Deleted
私のクエリが動作していない。いくつかの缶可能な助け。ありがとう
select person_name, appointment_id, unique_encounter
,Case when enounter_code = 'CG' then 'New' else '' End as enounter_code_1
,Case when enounter_code = 'AJ' then 'Updated' else '' End as enounter_code_2
,Case when enounter_code = 'DT' then 'Deleted' else '' End as enounter_code_3
from appointment
group by person_name, appointment_id, unique_encounter
が、私はそれを把握することができました。 – user3376315
http://stackoverflow.com/questions/5652334/how-to-convert-row-to-column-in-sql/5653301#5653301 – SQLMason