----------------------------------------------------------------
-- 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
*/
-- 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
*/
解决方案 »
- 如何用SQL截取字符串
- 执行动态SQL语句时传入参数,如果参数是动态生成,那怎么办啊,问了好久了都没人解决,请教邹建大哥
- 请教SQL语句的写法?
- 这个SQL语句怎么写?谢谢
- 游标中可以嵌套游标吗?可否帮我看看这个存储过程该怎么写
- 如何使用Office Developer XP建立SQLServer的工作流?
- 急!!!!
- VC编写服务器程序访问SQL SERVER数据库时的出现的问题(急,在线等贴,高额给分)
- SQL SERVER中“视图”和“存储过程“有何异同?
- 请教:Windows98下的SQl Server中如何创建数据库?
- 请问,如何通过字段位置查询
- sql2008 r2发送邮件(添加附件)
select t2 from 表 group by t2 having count(*)=1