日期:2014-05-17 浏览次数:20563 次
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-11-27 14:03:25
-- Version:
-- Microsoft SQL Server 2012 (SP1) - 11.0.3128.0 (X64)
-- Dec 28 2012 20:23:12
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.2 <X64> (Build 9200: )
--
----------------------------------------------------------------
--> 测试数据:[T1]
if object_id('[T1]') is not null drop table [T1]
go
create table [T1]([ID] int,[a] varchar(1),[b] varchar(1),[c] varchar(1))
insert [T1]
select 22,'q','w','e' union all
select 24,'q','w','e' union all
select 25,'q','w','e' union all
select 27,'s','d','f' union all
select 29,'a','s','d' union all
select 31,'a','s','d'
--------------开始查询--------------------------
select max(id) id ,a,b,c
from t1
group by a,b,c
----------------结果----------------------------
/*
id a b c
----------- ---- ---- ----
31 a s d
25 q w e
27 s d f
*/