select query其中count = value

时间:2013-11-22 17:52:27

标签: sql ms-access count ms-access-2010 where

我想创建一个像这样的查询

SELECT data.Category, data.Company, data.Email
FROM data
WHERE (((data.Category) Like "*Real estate*") AND ((data.Company) Not Like "*CBRE*" And (data.Company) Not Like "*Ellis*" And (data.Company) Not Like "*Douglas*"));

所以它会显示表格中记录少于11的公司的所有电子邮件

我的问题在于计数功能

1 个答案:

答案 0 :(得分:4)

我相信你正在寻找以下内容:

SELECT d.Category, d.Company, d.Email
FROM data AS d
WHERE d.Category LIKE "*Real estate*"
AND 
  (
    d.Company NOT LIKE "*CBRE*" 
    AND d.Company NOT LIKE "*Ellis*" 
    AND d.Company NOT LIKE "*Douglas*"
  )
GROUP BY d.Category, d.Company, d.Email
HAVING COUNT(*) < 11