如何提取最大值的一行,求助!!!!!!!!!!急急急!!!!!!1
例如提取count_num中最的值的一行,即提取出来的一行应为
22005-08-07 00:00:00.000 以及22005-09-12 00:00:00.000
count_num end_time
12005-08-06 00:00:00.000
22005-08-07 00:00:00.000
22005-09-12 00:00:00.000
12005-12-21 00:00:00.000
[解决办法]
--> 测试数据:[test]if object_id('[test]') is not null drop table [test]create table [test]([count_num] int,[end_time] datetime)insert [test]select 1,'2005-08-06 00:00:00.000' union allselect 2,'2005-08-07 00:00:00.000' union allselect 2,'2005-09-12 00:00:00.000' union allselect 1,'2005-12-21 00:00:00.000'select * from test awhere a.count_num=(select MAX(b.count_num) from test b)/*count_num end_time2 2005-08-07 00:00:00.0002 2005-09-12 00:00:00.000*/
[解决办法]
select count_num ,end_time from 表 having count_num =max(count_num) group by count_num