日期:2014-05-18 浏览次数:20494 次
select * from tb t where A2=(select max(A2) from tb where A1=t.A1)
------解决方案--------------------
select A1,max(A2) 'maxA2' from TB group by A1
------解决方案--------------------
select A1,max(A2)from A group by A1
------解决方案--------------------
SELECT A1,A2 FROM ( SELECT A1,A2,ROW_NUMBER() OVER (PARTITION BY A1 ORDER BY A2 DESC) AS RowIndex FROM TBA ) X WHERE RowIndex=1
------解决方案--------------------
use test go -->>>苦苦的潜行者 if object_id('tb') is not null drop table tb create table tb(A1 varchar(20),A2 int) insert tb select 'B1业务',12 union all select 'B3业务',14 union all select 'B1业务',52 union all select 'B2业务',16 union all select 'B1业务',12 union all select 'B2业务',82 union all select 'B2业务',14 go select A1,max(A2) as [最大量] from tb group by A1 /* (所影响的行数为 3 行) A1 最大量 ----- ---- B1业务 52 B2业务 82 B3业务 14 */ go drop table tb
------解决方案--------------------
如果仅仅是两个字段分组求最大,则直接分组,使用max即可,所以2楼效率高.