![mysql 多条件:mysql isnull](https://p3-tt.byteimg.com/large/tos-cn-i-0004/705c23a8decc49c89e0a8e24f1d06ff9.jpg)
首先判断变量是否存在,然后动态生成sql查询条件.php类似代码如下:<?php$where="1=1";$sulv=2;if($sulv){$where.="andsulv=".$sulv;}//其他条件也要使用if语句判断条件是否存在$sql="select*fromtablewhere".$where."orderbyiddesc";?>
![mysql 多条件:mysql isnull]()
![mysql 多条件:mysql isnull](https://p3-tt.byteimg.com/large/tos-cn-i-0004/705c23a8decc49c89e0a8e24f1d06ff9.jpg)
如果表结构都相同selectcount(*)form(select*from(select*fromdabanunionselect*ffromzhongbanunionselect*fromxiaoban)whereto_days(regtime)=to_days(now()))。
select*fromtablewhereuid='1'and(status='1'orstatus='3')select*fromtablewhere(uid='1'andstatus='1')orstatus='3'我还木看懂楼主的意思,希望这两条sql对你有所帮助。
![mysql 多条件:mysql isnull]()
![mysql 多条件:mysql isnull](https://p1-tt.byteimg.com/large/tos-cn-p-0000/ac06d7265d944034878a07410ec05d46.jpg)
mysql在创建索引后对索引的使用方式分为两种:1由数据库的查询优化器自动判断是否使用索引;2用户可在写sql语句时强制使用索引下面就两种索引使用方式进行说明。
![mysql 多条件:mysql isnull]()
![mysql 多条件:mysql isnull](https://p9-tt.byteimg.com/large/tos-cn-i-0004/eb71460639a647d2ac4f5e7030e1f279.jpg)
selectjg_1,jg_2,jg_3from表名whereid=1unionallselectjg_1,0,0from表名whereid=2第二个sql语句中2个0是字符常量,楼主可以随便填,是为了保持和第一句sql语句中有相同的列数。
![mysql 多条件:mysql isnull]()
![mysql 多条件:mysql isnull](https://p3-tt.byteimg.com/large/pgc-image/f1fff6dffc124ad0a8cd548394d09d59.jpg)