日期:2014-05-17 浏览次数:20555 次
with tb(name,server,bb)as(
select 'a','server1','bb1' union all
select 'a','server1','bb1' union all
select 'b','server2','bb1' union all
select 'b','server2','bb1' union all
select 'a','server1','bb2' union all
select 'c','server1','bb1' union all
select 'd','server1','bb2'
)
select distinct * from tb a
where exists (select 1 from (select distinct * from tb)b group by server,bb
having COUNT(1)>1 and a.server=server and a.bb=bb)
----------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2013-05-14 17:29:29
-- 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)
--
----------------------------
--> 测试数据:[select_bb]
if object_id('[select_bb]') is not null drop table [select_bb]
go
create table [select_bb]([name] varchar(1),[server] varchar(7),[bb] varchar(3))
insert [select_bb]
select 'a','server1','bb1' union all
select 'a','server1','bb1' union all