-1

I have the following query:

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 ))

Now I get the error:

"Every derived table must have its own alias".

xeom
  • 13
  • 3
  • 1
    Error messages in MySQL are unusally helpful. If a derived table wants or needs an alias, give it one! :-) – Strawberry Dec 03 '13 at 17:38
  • 1
    What happened when, as suggested by the error code, you gave the derived table its own alias ? Or did you fail to follow the instructions given by the error code ? – ApplePie Dec 03 '13 at 17:38

1 Answers1

1

As the error says you have to name every derived table.

Try the following:

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
    )
Strawberry
  • 33,750
  • 13
  • 40
  • 57
Filipe Silva
  • 21,189
  • 5
  • 53
  • 68