返回匹配计数条件的记录

时间:2017-05-05 13:07:51

标签: ms-access

以下查询根据计数返回分组结果: -

SELECT c.CUSTOMER_NAME, Count(q.DATE_QUOTE_REQUESTED) AS CountOfDATE_QUOTE_REQUESTED
FROM TBLQUOTESNEW q LEFT JOIN TBLCUSTOMERSNEW c ON q.CUSTOMER_ID = c.CUSTOMERID
GROUP BY c.CUSTOMER_NAME
HAVING (((Count(q.DATE_QUOTE_REQUESTED))>4))
ORDER BY c.CUSTOMER_NAME;

如何查看未分组的结果,但继续考虑> 4的计数标准?

1 个答案:

答案 0 :(得分:1)

此查询仅用于返回没有引号的客户表...如果您需要引号数据,请尝试使用引号表加入此结果...

select * from TBLCUSTOMERSNEW cc where cc.CUSTOMER_NAME in 
 (SELECT c.CUSTOMER_NAME FROM TBLQUOTESNEW q LEFT JOIN TBLCUSTOMERSNEW c 
  ON q.CUSTOMER_ID = c.CUSTOMERID
  GROUP BY c.CUSTOMER_NAME
  HAVING (((Count(q.DATE_QUOTE_REQUESTED))>4))
 )
order by cc.CUSTOMER_NAME;