Using AVG() in Oracle SQL
- by Viet Anh
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!