MySQL中使用case when 语句实现多条件查询的方法
k7005,中国教师行动网,韩国性感mtv
举例如下:
数据表为demotable,字段有id, condition1,condition2,condition3,condition4,condition5
要求是查询demotable中,condition1,condition2,condition3,condition4,condition5五个字段中符合任意两个或两个以上的条件的内容。
可使用case when来实现这个条件,需要嵌套子查询语句
sql语句代码示例如下:
select * from demotable
where ((select case 1 when condition1满足条件 then 1 else 0 end from demotable )
+(select case 1 when condition2满足条件 then 1 else 0 end from demotable)
+(select case 1 when condition3满足条件 then 1 else 0 end from demotable)
+(select case 1 when condition4满足条件 then 1 else 0 end from demotable)
+(select case 1 when condition5满足条件 then 1 else 0 end from demotable))>=2
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!!
点击进行留言回复
相关文章:
-
-
-
-
-
-
-
-
-
-
-
mysql事务管理操作详解
本文实例讲述了mysql事务管理操作。分享给大家供大家参考,具体如下:本文内容: 什么是事务管理 事务管理操作 回滚点 默认的事务管理首发日期:2018...
[阅读全文]
网友评论