(SELECT discount_percent
FROM products
WHERE discount_percent > AVG(discount_percent)
我不确定自己做错了什么
答案 0 :(得分:2)
WHERE discount_percent >
(SELECT discount_percent
FROM products
WHERE discount_percent > AVG(discount_percent)
应为:
WHERE discount_percent > (SELECT AVG(discount_percent) FROM products)
子查询后您缺少右括号。但是更大的问题是您不能在WHERE
子句中使用聚合函数,因为聚合是在选择行之后 完成的。另外,您需要使查询仅返回一个结果,以便可以将其与>
进行比较。
答案 1 :(得分:1)
WHERE discount_percent > AVG(discount_percent)
可能需要更改为
HAVING discount_percent > AVG(discount_percent)
HAVING
子句用于过滤聚合函数,例如您正在调用的AVG
。
有关其他文档,请查看以下链接:http://www.mysqltutorial.org/mysql-having.aspx