[英]SQL union grouped by rows
Assume I have a table like this:假设我有一个这样的表:
col1 ![]() |
col2 ![]() |
col3 ![]() |
col4 ![]() |
---|---|---|---|
commonrow![]() |
one![]() |
two![]() |
null ![]() |
commonrow![]() |
null ![]() |
null ![]() |
three![]() |
How to produce a result to look like this:如何产生如下所示的结果:
col1 ![]() |
col2 ![]() |
col3 ![]() |
col4 ![]() |
---|---|---|---|
commonrow![]() |
one![]() |
two![]() |
three![]() |
Thanks谢谢
like this, you can group by col1 and get the maximum in each group:像这样,您可以按 col1 分组并获得每组中的最大值:
select col1 , max(col2) col2 , max(col3) col3 , max(col4) col4
from table
group by col1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.