日期:2014-05-17 浏览次数:20492 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-03-13 17:18:48
-- Version:
-- Microsoft SQL Server 2008 R2 (SP1) - 10.50.2500.0 (X64)
-- Jun 17 2011 00:54:03
-- Copyright (c) Microsoft Corporation
-- Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1, v.721)
--
----------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([A] varchar(1),[B] int,[C] int)
insert [huang]
select 'a',1,10 union all
select 'a',2,20 union all
select 'a',3,30 union all
select 'b',2,40 union all
select 'b',3,50 union all
select 'b',4,60 union all
select 'c',6,70 union all
select 'c',3,80 union all
select 'c',5,90
--------------开始查询--------------------------
select * from [huang] a
WHERE EXISTS (SELECT 1 FROM (SELECT a,MIN(b)b FROM huang GROUP BY a) b WHERE a.a=b.a AND a.b=b.b)
----------------结果----------------------------
/*
A B C
---- ----------- -----------
a 1 10
b 2 40