SQL语句中如何使用含有if....else...判断语句

sql中没有if语句,但有case语句,而且是所有数据库都支持的,
语法是case when 条件1 then 结果1 when 条件2 then 结果2 else 结果N end,
可以有任意多个条件,如果没有默认的结果,最后的else也可以不写,
select case when col1 > 1 then col2 else col3 end from XXXtable
发布了195 篇原创文章 · 获赞 52 · 访问量 31万+

猜你喜欢

转载自blog.csdn.net/hongweideng/article/details/48972139