【发布时间】:2021-07-18 09:56:59
【问题描述】:
【问题讨论】:
标签: sql sql-server tsql
【问题讨论】:
标签: sql sql-server tsql
您可以使用条件聚合:
select max(case when col1 = 'a' then e end) as a_e,
max(case when col1 = 'a' then f end) as a_f,
max(case when col1 = 'a' then g end) as a_g,
max(case when col1 = 'b' then e end) as b_e,
max(case when col1 = 'b' then f end) as b_f,
max(case when col1 = 'b' then g end) as b_g,
max(case when col1 = 'c' then e end) as c_e,
max(case when col1 = 'c' then f end) as c_f,
max(case when col1 = 'c' then g end) as c_g,
max(case when col1 = 'd' then e end) as d_e,
max(case when col1 = 'd' then f end) as d_f,
max(case when col1 = 'd' then g end) as d_g
from t;
【讨论】: