当前位置: 代码迷 >> Sql Server >> 怎么提取最大值的一行,1
  详细解决方案

怎么提取最大值的一行,1

热度:37   发布时间:2016-04-27 12:10:24.0
如何提取最大值的一行,求助!!!!!!!!!!急急急!!!!!!1
例如提取count_num中最的值的一行,即提取出来的一行应为  
2 2005-08-07 00:00:00.000 以及2 2005-09-12 00:00:00.000

count_num end_time
1 2005-08-06 00:00:00.000
2 2005-08-07 00:00:00.000
2 2005-09-12 00:00:00.000
1 2005-12-21 00:00:00.000


------解决方案--------------------
SQL code
--> 测试数据:[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
  相关解决方案