2013-04-18 55 views
0

我試圖使用select查詢來顯示我的數據庫中所有在過去發出超過5個投訴的客戶。我試過這個查詢:使用聚合函數作爲過濾條件的SQL

SELECT customer_ID, COUNT(customer_feedback.feedback_type) AS complaints 
FROM customer_feedback 
WHERE complaints>5 
GROUP BY customer_ID; 

但它不起作用。 Access無法識別WHERE子句中的表達式「抱怨」。所以我試過了,這更糟糕:

SELECT customer_ID, COUNT(customer_feedback.feedback_type) AS complaints 
FROM customer_feedback 
WHERE COUNT(customer_feedback.feedback_type)>1 
GROUP BY customer_ID; 

我確定有一個簡單的解決方案,我現在無法想象。

回答

1

在SQL Server,這將是該組的 「具有」 子句份

select something, count(*) 
from somewhere 
group by something 
having count(*) > 5 
2
SELECT customer_ID, COUNT(customer_feedback.feedback_type) AS complaints 
FROM customer_feedback 
GROUP BY customer_ID 
HAVING COUNT(customer_feedback.feedback_type)>5;