目前工作中用到的sql语句

来源:互联网 发布:汽泡水 知乎 编辑:程序博客网 时间:2024/04/27 22:42

 1、满足任意两个条件查询 



select * from 表名
where
(case when 条件1 then 1 else 0 end+
case when 条件2 then 1 else 0 end+
case when 条件3 then 1 else 0 end+
case when 条件4 then 1 else 0 end)>=2

(如果用户输入一个条件就查不出来,怎么让用户输入一个条件、多个条件 都能查询)


2、数据库里日期 用varchar存储  年月日时分秒 例 2017-12-22 08:22:23   用年月日查询 


select * from 表名 
WHERE 条件一
    OR     条件二
    OR substr(时间字段,1,10)='2017-12-22'  //substr截取



    

原创粉丝点击