数据库问题,请各位大虾帮帮忙,下面的问题小弟我不知道该如何写SQL语句

来源:百度知道 编辑:UC知道 时间:2024/09/21 19:32:52
现有一张学生信息表(表名为student),学生的年龄和姓名的列名分别为age和name,要查询年龄最大的学生的姓名,应该如何写SQL语句。
我本来是想这样写SQL语句的“select name from student where age = max(age)”,但是书上说计算函数(max)不能出现在where子句中,那我应该怎样写呀,请各个大虾帮帮忙吧,小弟万分感谢!!

select name from student where age=(select max(age) from student)

select name from student where age=(select max(age) from student)

通过子查询select max(age) from student中的聚合函数Max,可以查询到最大年龄。然后在查表,条件满足最大年龄的记录就可以了。

SELECT name
FORM student
WHERE age=(SELETE max(age)
FORM student)

我毕业1整年了,想着给你写的,不敢保证一定对,但是应该没什么错,呵呵。

按年龄排序,最大的放前面,取第一条数据就行了,如下:
SELECT TOP 1 name
FROM student
ORDER BY age DESC

select age,name
from student
where sage>=(select max age,name
from student
)