大佬教程收集整理的这篇文章主要介绍了重复行时的 SQL case 语句,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
目标:col: ID 必须是唯一的,不能重复
问题:当 ID_catelog1
为空时,ID_catelog2
会启动但会生成多行,因为其中一些行有多个 ID_catelog2
。
对于多个,我需要将“multiple”放在 ID_catelog_final
而不是 ID_catelog2
下。
这是我目前的查询:
SELEct disTinct
ID,name,ID_catelog1,Large_ID_catelog2,case
when ID_catelog1 is null
then ID_catelog2
else ID_catelog1
end as ID_catelog_final
from
table
where
ID is not null;
我认为您希望使用条件逻辑进行聚合:
SELEct id,name,(case when max(coalesce(id_catelog1,Large_id_catelog2)) =
min(coalesce(id_catelog1,Large_id_catelog2))
then min(coalesce(id_catelog1,Large_id_catelog2))
else 'multiple'
end)
from t
group by id,name
以上是大佬教程为你收集整理的重复行时的 SQL case 语句全部内容,希望文章能够帮你解决重复行时的 SQL case 语句所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。