日期:2014-05-18  浏览次数:20405 次

[SQL语句紧急求助!!] 在某个表的一组记录中,如何取到 某一列中值最大的字段所对应的记录
不想取到一组记录后用order   by的方法,不知道有没有其他的方法,让数据库仅返回该条符合条件的纪录,比如max()?

例如,有下面这个表,记录这个月发生的各种出差费用,每一笔出差费用对应一条记录。如何查到张三这个月出差费用支持最多的那条记录?

人名       费用         地点   时间

张三       500           武汉     5.11
李四       300           武汉     5.5
张三       700           广州     5.20
王五       800           上海     5.27
李四       400           北京     5.26
张三       550           成都     5.12

则所期望得到的张三的纪录为
张三       700           广州     5.20

谢谢各位答人


------解决方案--------------------
select *
from 表 as t
where 费用 =(select max(费用) from 表 where 人名=t.人名)
and 人名= '张三 '
------解决方案--------------------
select a.* from tb a,
(
select max(费用) 费用 from tb where 人名 = '张三 '
) b
where 人名 = '张三 ' and a.费用 = b.费用
------解决方案--------------------
select * from t1 where 费用 =(select max(费用) from t1 where 人名= '张三 ' )
and 人名= '张三 '

------解决方案--------------------
select a.* from tb a,
(
select max(费用) 费用 from tb where 人名 = '张三 '
) b
where 人名 = '张三 ' and a.费用 = b.费用

------解决方案--------------------
select *
from 表 as t
where 费用 =(select max(费用) from 表 where 人名=t.人名 and date1= '2007-08 ')
and 人名= '张三 '
and date1= '2007-08 '