数据库一个字段同时满足多个条件的查询

数据库评论963字数 98阅读模式

一个字段需要同时等于多个值的时候,用and直接连不会有数据查出。

 很文博客-https://www.hinvn.com/12328.html

所以需要一些特殊处理。很文博客-https://www.hinvn.com/12328.html

  1. SELECT * FROM news_extinfo
  2. where
  3. (ExtID = 1 and OptionValue = 0)
  4. or (ExtID = 2 and OptionValue = 0 )
  5. or (ExtID = 3 and OptionValue = 0 )
  6. group by NewsID
  7. having count(*)=3

此处 count(*) = 3 表示的意思是很文博客-https://www.hinvn.com/12328.html

在查询的结果中,只查出按group 分组之后,每个组的有3条数据的结果集很文博客-https://www.hinvn.com/12328.html 很文博客-https://www.hinvn.com/12328.html

weinxin
我的微信
微信号已复制
扫一扫更精彩
大家的支持是我更新的动力!!!
匿名

发表评论

匿名网友