我有以下查询:
SELECT SN,SUM(QTY) FROM SP GROUP BY SN HAVING SUM(QTY)>(SELECT AVG(SUM(QTY)) FROM (SELECT SUM(QTY) FROM SP GROUP BY SN ))
现在我收到了错误:
“每个派生表都必须有自己的别名”。
答案 0 :(得分:1)
如错误所示,您必须为每个派生表命名。
尝试以下方法:
SELECT SN, SUM(QTY)
FROM SP
GROUP BY SN
HAVING SUM(QTY) > (
SELECT AVG(z)
FROM (
SELECT SUM(QTY) z
FROM SP
GROUP BY SN
) a
)