Sql 以具有相同数据的多列为轴心
我有一套数据 我怎样才能做到这一点Sql 以具有相同数据的多列为轴心,sql,sql-server,pivot,pivot-table,aggregate-functions,Sql,Sql Server,Pivot,Pivot Table,Aggregate Functions,我有一套数据 我怎样才能做到这一点 您可以使用条件聚合: select targetchildid, max(case when name = 'Hepatitis B #1' then datereceived end) as hepatitis_b1_date_received, max(case when name = 'Hepatitis B #1' then ajustedduedate end) as hepatitis_b1_adjusted_due_date
您可以使用条件聚合:
select targetchildid,
max(case when name = 'Hepatitis B #1' then datereceived end) as hepatitis_b1_date_received,
max(case when name = 'Hepatitis B #1' then ajustedduedate end) as hepatitis_b1_adjusted_due_date,
max(case when name = 'Hepatitis B #1' then isskipped end) as hepatitis_b1_adjusted_is_skipped,
max(case when name = 'Hepatitis B #2' then datereceived end) as hepatitis_b2_date_received,
max(case when name = 'Hepatitis B #2' then ajustedduedate end) as hepatitis_b2_adjusted_due_date,
max(case when name = 'Hepatitis B #2' then isskipped end) as hepatitis_b2_adjusted_is_skipped,
max(case when name = 'Hepatitis B #3' then datereceived end) as hepatitis_b3_date_received,
max(case when name = 'Hepatitis B #3' then ajustedduedate end) as hepatitis_b3_adjusted_due_date,
max(case when name = 'Hepatitis B #3' then isskipped end) as hepatitis_b3_adjusted_is_skipped
from mytable
group by targetchildid
请让我们看看你的尝试。请使用格式化文本而不是图像。