日期:2014-05-18 浏览次数:20580 次
select count(name) from Test group by name Having count(name)> 1
select * from test1 where [name] in (select [name] from test1 group by [name] having count(test1.[name])<>1)
select id, name from test1 group by id,name having count(test1.name) > 1
SELECT NAME,ID FROM TEST1 T1 WHERE EXISTS( SELECT 1 FROM TEST1 T2 WHERE T2.NAME=T1.NAME AND T2.ID<>T1.ID ) ORDER BY NAME,ID
------解决方案--------------------
SELECT * FROM TEST A WHERE EXISTS ( SELECT 1 FROM TEST WHERE NAME = A.NAME AND ID <> A.ID )
------解决方案--------------------
--> 测试数据:[test] if object_id('[test]') is not null drop table [test] create table [test]([id] varchar(3),[name] varchar(3)) insert [test] select '001','aaa' union all select '002','aaa' union all select '003','bbb' union all select '004','ccc' select * from test a where exists(select 1 from test b where a.name=b.name and a.id<>b.id) /* id name 001 aaa 002 aaa */ --这个结果?
------解决方案--------------------