id t1 t2
1 123 ddd
2 111 ddd
3 222 eee
4 333 fff
结果
eee
fff
求语句。
------解决方案--------------------
----------------------------------------------------------------
-- Author :DBA_Huangzj(發糞塗牆)
-- Date :2014-01-09 14:15:34
-- 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: )
--
----------------------------------------------------------------
--> 测试数据:[huang]
if object_id('[huang]') is not null drop table [huang]
go
create table [huang]([id] int,[t1] int,[t2] varchar(3))
insert [huang]
select 1,123,'ddd' union all
select 2,111,'ddd' union all
select 3,222,'eee' union all
select 4,333,'fff'
--------------开始查询--------------------------
select t2
from [huang]
GROUP BY t2
HAVING COUNT(t2)=1
----------------结果----------------------------
/*
t2
----
eee
fff
*/