English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

I was under the impression that SQL went FROM, WHERE, GROUP BY, HAVING, SELECT, ORDER BY. Is that not correct?

I've got the query
SELECT A.cruisingrange, AVG(E.salary) AS avgsal, A.aname
FROM employees AS E, aircraft AS A, certified AS C
WHERE A.aid = C.aid AND C.eid = E.eid
GROUP BY A.aname
HAVING A.cruisingrange > 1000;

but it breaks if I take out A.cruisingrange in the SELECT statement. I do not want it to return A.cruisingrange.

Thanks!

2007-09-16 12:18:44 · 2 answers · asked by dawhitfield 3 in Computers & Internet Programming & Design

2 answers

Move cruisingrange from HAVING to WHERE, and take cruisingrange out of the SELECT clause.

2007-09-16 12:29:12 · answer #1 · answered by ? 7 · 0 0

HAVING clause is similar like WHERE for conditional query, the difference is HAVING is conditional for aggregation function like AVG, SUM, COUNT, etc...in your problem, you can remove A.cruisingrange and change the 'HAVING A.cruisingrange>1000' into 'HAVING avgsal > 1000'

2007-09-16 12:32:42 · answer #2 · answered by Lastiko W 2 · 0 1

fedest.com, questions and answers