表结构:
表A(a,b)两列
表B(a,c,d)三列现在我要实现类似下面的语句
select A.* from A where A.a in(select B.a from B where B.d in
(select B.d,count(*) cc from B
group by B.d
having count(*)>1)
)很明显上面的语句是不对的 我只是描述一下这个意思
希望各位帮忙解决下 先谢过
表A(a,b)两列
表B(a,c,d)三列现在我要实现类似下面的语句
select A.* from A where A.a in(select B.a from B where B.d in
(select B.d,count(*) cc from B
group by B.d
having count(*)>1)
)很明显上面的语句是不对的 我只是描述一下这个意思
希望各位帮忙解决下 先谢过
表A的a和表B的a是关联的
在表B中筛选出d列重复的条数大于1的数据不知道这样说清楚不...
declare @t1 table( a int,b int )declare @t2 table( a int, c int , d int )insert into @t1 values(1,1)
insert into @t1 values(2,1)
insert into @t2 values(1,2,null)
insert into @t2 values(2,1,2)select * from @t1 where a in (select a from @t2 where d is not null )看看是否满足需求
意思是整个意思,但是条件不对
是求的d中重复的数据,不是为null的
insert into @t1 values(2,1)
insert into @t1 values(3,1)
insert into @t2 values(1,2,1)
insert into @t2 values(2,1,2)
insert into @t2 values(3,1,2)select A.* from @t1 A
inner join @t2 B on B.a = A.a
inner join(
select d from @t2 group by d having Count(*)>1)C on C.d = B.d是你3楼说的需求用这个
select A.* from A where A.a in(select B.a from B where B.d in
(select B.d from B
group by B.d
having count(*)>1)
)