I am doing a query on table to take multiple lines that share multiple pieces of information and form them into one line. The only differences between these lines is several columuns that are Y
or N
. I would like the ones that have Y
to override those have have N
and if there are no Y
, then N
should be seen.
An example of my current table
col 1 col 2 col 3 col 4
AZ99ZB102 8 Y N
AZ99ZB102 8 Y Y
AZ99ZB201 4 N N
AZ99ZB201 4 Y N
Expected Result:
col 1 col 2 col 3 col 4
AZ99ZB102 8 Y Y
AZ99ZB201 4 Y N
Any help on this would be greatly appreciated.
You can do this with basic aggregation:
select col1, col2, max(col3) as col3, max(col4) as col4
from table
group by col1, col2;
I took the liberty of renaming the columns to be "col" rather than "row". The latter seems totally confusing.
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.