create table #a ( studentno char(11), sname varchar(8), sex varchar(4), birthday date ) insert into #a select '18122210009','许东山','男','1999-11-05' union all select '18122221324','何白露','女','2000-12-04'union all select '18125121107','敬横江','男','2000-03-01'union all select '18125121107','粱一苇','女','1999-09-03'union all select '19120000111','韩山川','男','2000-02-05'select top 1 datediff(year,birthday,getdate()) as 最大年龄,* from #a where sex='男' order by 最大年龄 desc我用的sqlserver,不知道结果和你的怎么样,但是我没报错
(
studentno char(11),
sname varchar(8),
sex varchar(4),
birthday date
)
insert into #a select '18122210009','许东山','男','1999-11-05' union all
select '18122221324','何白露','女','2000-12-04'union all
select '18125121107','敬横江','男','2000-03-01'union all
select '18125121107','粱一苇','女','1999-09-03'union all
select '19120000111','韩山川','男','2000-02-05'select top 1 datediff(year,birthday,getdate()) as 最大年龄,*
from #a
where sex='男'
order by 最大年龄 desc我用的sqlserver,不知道结果和你的怎么样,但是我没报错