一個(gè)字段同時(shí)滿足多個(gè)條件的查詢

當(dāng)一個(gè)字段需要同時(shí)等于多個(gè)值的時(shí)候,用and直接連不會(huì)有數(shù)據(jù)查出。

所以需要一些特殊處理。
代碼如下:
select * FROM news_extinfo
where
(ExtID = 1 and OptionValue = 0)
or (ExtID = 2 and OptionValue = 0 )
or (ExtID = 3 and OptionValue = 0 )
group by NewsID
having count(*)=3

此處 count(*) = 3 表示的意思是

在查詢的結(jié)果中,只查出按group 分組之后,每個(gè)組的有3條數(shù)據(jù)的結(jié)果集

? 版權(quán)聲明
THE END
喜歡就支持一下吧
點(diǎn)贊8 分享