[英]How to select only those rows where one column can have null or not null values for the same id
你的描述不是很清楚。 如果我确实正确理解了您的要求,那么每个col1
只需要 1 行。 选择值最多不是 null 的行?
select *
from
(
select *, rn = row_number() over (partition by col1
order by case when col2 is not null then 1 else 0 end
+ case when col3 is not null then 1 else 0 end
+ case when col4 is not null then 1 else 0 end
desc)
from a_table
) d
where rn = 1
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.