SELECT
pro.`Name`,
pro.idProduct,
COUNT(DISTINCT pur.idPurchase) AS Sales
FROM
product AS pro
INNER JOIN purchase pur ON pur.idProduct = pro.idProduct
WHERE pro.idUser = '54c26fdac8f5c'
AND COUNT(DISTINCT pur.idPurchase) > '2'
GROUP BY pro.idProduct
我试图让所有购买的产品都大于2,所以我在where子句中尝试了这个以添加这个组功能
COUNT(DISTINCT pur.idPurchase) > '2'
但是我收到了这个错误
无效使用群组功能
答案 0 :(得分:0)
试试这个:
SELECT
pro.`Name`,
pro.idProduct,
COUNT(DISTINCT pur.idPurchase) AS Sales
FROM
product AS pro
INNER JOIN purchase pur ON pur.idProduct = pro.idProduct
WHERE pro.idUser = '54c26fdac8f5c'
GROUP BY pro.`Name`, pro.idProduct
HAVING COUNT(DISTINCT pur.idPurchase) > '2'