简体   繁体   中英

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:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM