Using AVG() in Oracle SQL

Posted by Viet Anh on Stack Overflow See other posts from Stack Overflow or by Viet Anh
Published on 2012-10-15T20:32:35Z Indexed on 2012/10/15 21:37 UTC
Read the original article Hit count: 292

Filed under:
|
|
|

I have a table named Student as followed:

CREATE TABLE  "STUDENT" 
(   "ID" NUMBER(*,0), 
    "NAME" VARCHAR2(20), 
    "AGE" NUMBER(*,0), 
    "CITY" VARCHAR2(20), 
    PRIMARY KEY ("ID") ENABLE
)

I am trying to get all the records of the students having a larger age than the average age. This is what I tried:

SELECT *
FROM student
WHERE age > AVG(age)

and

SELECT * 
FROM student
HAVING age > AVG(age)

Both ways did not work!

© Stack Overflow or respective owner

Related posts about sql

Related posts about Oracle