select*fromtablewhere(name1like'%key1%'orname2like'%key2%'orname3like'%key3%')同理,你還可以任意再次組合,用or連接就行如再上name1likekey1orname1likekey2orname1likekey3name2likekey1orname2likekey2orname2likekey3等等。
- 文化問答
- 答案列表
mysql多條件查詢:mysql多where條件[朗讀]
如果表結構都相同selectcount(*)form(select*from(select*fromdabanunionselect*ffromzhongbanunionselect*fromxiaoban)whereto_days(regtime)=to_days(now()))。
標準的方法是使用union聯合或者case,我認為case最好,聯合的結果被混淆了,我寫一個case的例子你試試看:selectsum(casewhen`id1`=1and`check`='b'then1else0end)cnt1,sum(casewhen`id2`=0and`check`='b'then1else0end)cnt2,sum(casewhen`id3`=1and`check`='c'then1else0end)cnt3,from`table`;語句輸出的結果是這樣的,非常直觀吧:cnt1cnt2cnt3235。
selectjg_1,jg_2,jg_3from表名whereid=1unionallselectjg_1,0,0from表名whereid=2第二個sql語句中2個0是字符常量,樓主可以隨便填,是為了保持和第一句sql語句中有相同的列數。
select*fromtablewhereuid='1'and(status='1'orstatus='3')select*fromtablewhere(uid='1'andstatus='1')orstatus='3'我還木看懂樓主的意思,希望這兩條sql對你有所幫助。