我正在使用这个MySQL查询获取buy_count大于3的购买频率,有人能告诉我如何在where子句中使用count(id)?我尝试使用count(id)> 3,但它不起作用。
SELECT
id,
COUNT(id) AS buying_count,
buyer_name
FROM
c_customer_orders
GROUP BY buyer_email
答案 0 :(得分:2)
SELECT
id,
COUNT(id) AS buying_count,
buyer_name
FROM
c_customer_orders
GROUP BY buyer_email
HAVING buying_count > 3
答案 1 :(得分:0)
试试这个:
SELECT
id,
COUNT(id) AS buying_count,
buyer_name
FROM
c_customer_orders
GROUP BY buyer_email
HAVING buying_count >= 3