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

Sql 计算查询,为每种ID语言添加“CustomDescription”列,sql,sql-server,Sql,Sql Server,请帮我找出如何为我添加到表中的每个idLanguage创建一个临时计算字段customDescription2、customDescription3?下表中显示的数据来自表1 如果您知道语言ID,则可以使用条件聚合: select substitute, barcode, max(case when idlanguage = 1 then customDescription end) as customDescription1, max(case when idlan

请帮我找出如何为我添加到表中的每个idLanguage创建一个临时计算字段customDescription2、customDescription3?下表中显示的数据来自表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;

欢迎来到StackOverflow。请访问,采取的,看看什么和。做一些研究,搜索相关话题等;如果您遇到困难,请发布您的尝试,并记录输入和预期输出。您使用的是哪种产品?SQL只是一种查询语言,而不是特定数据库产品的名称。请为使用postgresql、oracle、sql server、db2的数据库产品添加一个……我使用的是mssql server谢谢Gordon。你的解决方案是完美的。