日期:2014-05-17 浏览次数:20443 次
select 名称
from (
select distinct * from tb)t
group by 名称
having COUNT(*)>1
;with tb as
(
select 'A' as 名称,12 as 价格
union all select 'A',13
union all select 'B',12
union all select 'B',12
union all select 'C',14
)
select 名称
from (
select distinct * from tb)t
group by 名称
having COUNT(*)>1
结果:
/*
A
*/
create table test (name nvarchar(10),price int)
insert into test values('A',12)
insert into test values('A',13)
insert into test values('B',12)
insert into test values('B',12)
insert into test values('C',14)
insert into test values('C',12)
insert into test values('B',12)
insert into test values('C',13)
select t.name
from test t
INNER JOIN test e
on t.name=e.name
where e.price<>t.price
group by t.name
/*
name
A
C
*/