SQL avg syntax
SELECT AVG(column_name) FROM table_name
New table:
StudentS
S_id Grade Name phone
1 98 Xiao Ming 123456
2 97 Xiao Huang 232456
3 95 Xiao Li 987654
4 93 Xiao Xiao 654321
5 90 Wei Wei 321065
查询:
SELECT AVG(Grade) AS GradeAverage FROM StudentS
Result:
GradeAverage
94
We want to find the names of students whose Grade values are higher than the average Grade.
查询:
SELECT Name FROM StudentS
WHERE Grade>(
SELECT AVG(Grade) FROM StudentS
Effect:
Name
1 Xiaoming2
Xiaohuang3
Xiaoli
2018-04-27 14:37:59