SQL 并集按行分组
SQL union grouped by rows
假设我有这样一个 table:
col1
col2
col3
col4
commonrow
one
two
null
commonrow
null
null
three
如何生成如下所示的结果:
col1
col2
col3
col4
commonrow
one
two
three
谢谢
像这样,可以按col1分组,取每组中的最大值:
select col1 , max(col2) col2 , max(col3) col3 , max(col4) col4
from table
group by col1
假设我有这样一个 table:
col1 | col2 | col3 | col4 |
---|---|---|---|
commonrow | one | two | null |
commonrow | null | null | three |
如何生成如下所示的结果:
col1 | col2 | col3 | col4 |
---|---|---|---|
commonrow | one | two | three |
谢谢
像这样,可以按col1分组,取每组中的最大值:
select col1 , max(col2) col2 , max(col3) col3 , max(col4) col4
from table
group by col1