【发布时间】:2020-09-14 04:30:14
【问题描述】:
在 SQL Server 中,我正在尝试将表 1 转换为表 2。通过从堆栈溢出中读取其他答案,我可以执行某种 row_number()。但问题是我需要在转换后进行一些内部连接,因为以下脚本使用max() 聚合函数,它会强制其他表中的其他字段也具有某种聚合函数。所以我想知道是否有替代方法来解决这个问题?或者如果有办法在与另一个表连接时处理这个聚合函数。
select max(case when key = 'ab' then Value end) as ab,
max(case when key = 'cd' then Value end) as cd
from (select t.*,
row_number() over (partition by key order by Value) as seq
from table t
) t
group by seq;
表 1
表 2
【问题讨论】:
-
提供其他表格的一些样本数据以及您想要的输出
-
当有人回答您的问题时,您是否熟悉预期的礼仪?我注意到您没有接受任何问题的单一答案。我建议阅读what to do when someone answers,然后为您现有的问题提供一些答案和支持。
标签: sql sql-server database pivot