【问题标题】:SQL union grouped by rows按行分组的 SQL 联合
【发布时间】:2021-06-03 13:24:27
【问题描述】:

假设我有一张这样的表:

col1 col2 col3 col4
commonrow one two null
commonrow null null three

如何生成如下所示的结果:

col1 col2 col3 col4
commonrow one two three

谢谢

【问题讨论】:

  • 非常感谢 @eshirvana 和对 marc_s 的编辑

标签: sql database group-by union union-all


【解决方案1】:

像这样,你可以按 col1 分组,得到每组的最大值:

select col1 , max(col2) col2 , max(col3) col3 , max(col4) col4
from table 
group by col1

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-08-12
    • 1970-01-01
    • 2020-12-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多