读书人

sql抽出唯一的数据解决办法

发布时间: 2012-02-06 15:52:44 作者: rapoo

sql抽出唯一的数据
比如出现以下数据

name phone
aa 111
bb 111
aa 111
cc 111
aa 22
aa 1
bb 3333

想抽出的结果是:


name phone
aa 22
aa 1
bb 3333

应该怎做好的咯;我是这样的
select name,phone from table group by name,phone having count(phone)=1

当然这是错的咯;请指正

[解决办法]
select
t.name,t.phone
from
[table] t
where
1=(select count(*) from [table] where phone=t.phone)

读书人网 >SQL Server

热点推荐