为每种ID语言添加“ CustomDescription”列的计算查询

时间:2018-12-11 09:34:58

标签: sql sql-server

请您帮我弄清楚如何为我在表上添加的每个idLanguage创建一个临时计算字段(customDescription2,customDescription3…)。下表中显示的数据来自1表。

Before & After

1 个答案:

答案 0 :(得分:1)

如果您知道语言ID,则可以使用条件聚合:

select substitute, barcode,
       max(case when idlanguage = 1 then customDescription end) as customDescription1,
       max(case when idlanguage = 2 then customDescription end) as customDescription2,
       max(case when idlanguage = 3 then customDescription end) as customDescription3,
       max(case when idlanguage = 4 then customDescription end) as customDescription4
from t
group by substitute, barcode;