日期:2014-05-17 浏览次数:20542 次
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-01-17 09:51:43
-- 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)
--
----------------------------
--> 测试数据:[M]
if object_id('[M]') is not null drop table [M]
go
create table [M]([a] int,[b] int,[c] varchar(3))
insert [M]
select 1,56,'kl' union all
select 1,45,'yui' union all
select 2,89,'op' union all
select 2,34,'uy' union all
select 3,12,'hj' union all
select 3,65,'vb'
--------------开始查询--------------------------
SELECT *
FROM m a
WHERE EXISTS ( SELECT 1
FROM ( SELECT a ,
MIN(b) b
FROM [M]
GROUP BY A
) b
WHERE a.a = b.a
AND a.b = b.b )
----------------结果----------------------------
/*
(6 行受影响)
a b c
----------- ----------- ----
1 45 &nbs