1: select case A when ' ' then ( case B when ' ' then C else B end ) else A end from table_name
2: select
case
when A <> ' ' or A is not null then A
when B <> ' ' or B is not null then B
when C <> ' ' or C is not null then C
end
from table_name
从表中首先查询列A的值,当A为空时查询B的值,B为空时查询C的值
ps:新增2 更为严谨
本文深入探讨了SQL中Case语句的使用技巧,包括select case和when子句的结合运用,详细解析了如何通过Case语句实现数据字段的条件选择,当指定列为空时,如何依次检查后续列的值,为数据库查询提供了更灵活的选择方案。
428

被折叠的 条评论
为什么被折叠?



