简单查询问题(100分)
表中只有A字段
数据如下
A
XXXX
XXXX
YYYY
YYYY
DDDD
我想得到前4条语句,也就是如果A字段中有相同的记录就选出来。
DDDD只有一条,就不选他。
谢谢大家,在线百分答谢
[解决办法]
select * from [Table] where a in(
select a from [Table] group by a having count(1)> 1)
[解决办法]
select
a.*
from
tName a,
(select A,count(*) as cnt from tName group by A) b
where
a.A=b.A and b.cnt> 1
[解决办法]
select * from [Table] a where (select count(1) from [Table] where a=a.a)> 1
[解决办法]
declare @a table(a varchar(10))
insert into @a
select 'XXXX ' union all select 'XXXX '
union all select 'YYYY '
union all select 'YYYY '
union all select 'DDDD '
select * from @a where a in(select a from @a group by a having count(*) > 1)
结果
a
----------
XXXX
XXXX
YYYY
YYYY
[解决办法]
select * from A
where id in (select a ,count(*) from A group by a having count(*)> 1)