I'm continuing to get an ERROR CODE 1248 in mySQL
SELECT INV_NUM, AVG_INV, (INV_AMOUNT - AVG_INV) AS DIFF
FROM CH08_INVOICE,
(SELECT AVG(INV_AMOUNT) AS AVG_INV FROM CH08_INVOICE)
GROUP BY INV_NUM, AVG_INV, INV_AMOUNT- AVG_INV;
Asked
Active
Viewed 62 times
-1

Philip Olson
- 4,662
- 1
- 24
- 20

Abby Schukei
- 45
- 5
-
1I see potentially more than one problem with this query, but I can tell you that error code 1248 implies that you are missing an alias on a table. This is most likely coming from the inner `SELECT` but then again there may be other problems. – Tim Biegeleisen Oct 07 '15 at 01:46
-
Indeed. Every derived table (select within a select) must have its own alias. – GolezTrol Oct 07 '15 at 01:49
-
Where do I add the alias on the inner SELECT? – Abby Schukei Oct 07 '15 at 01:49
-
Possible duplicate of [mysql error code 1248](http://stackoverflow.com/questions/17718444/mysql-error-code-1248) – Mephy Oct 07 '15 at 01:50
2 Answers
2
SELECT INV_NUM, AVG_INV, (INV_AMOUNT - AVG_INV) AS DIFF
FROM CH08_INVOICE,
(SELECT AVG(C2.INV_AMOUNT) AS AVG_INV FROM CH08_INVOICE C2) AS T
GROUP BY INV_NUM, AVG_INV, INV_AMOUNT- AVG_INV;
I'm not sure you need the group by, since you do not aggregate the invoice amount.

Shadow
- 33,525
- 10
- 51
- 64
1
You need to add alias name for your inner query.Something similar to :
(SELECT AVG(c.INV_AMOUNT) AS AVG_INV FROM CH08_INVOICE c)
As both the inner query and outer query are working on the same table

S.KC
- 71
- 6