简体   繁体   中英

Get all distinct values from column1 in case of 2 similar rows, get the one with column2 not null

I have a large table as dataset. If there are 2 similar rows with same date and id then how do I get the row for which another column value is not null?

SELECT *, row_number() 
   over (partition by id order by date desc) rowNumber 
FROM table where rowNumber = 1;

Please try this query:

select * from table where (id, date) in 
(select id, date from table group by id, table having count(1) > 1) 
and value is not null;

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