34,590
社区成员
发帖
与我相关
我的任务
分享
create table #TT
(
product varchar(10),
[month] int,
number int
)
insert into #TT select 'aa',2,30
union all select 'aa',3,60
union all select 'bb',2,30
union all select 'bb',3,30
select * from #TT t where exists (select * from #TT where t.product=product and number<>t.number) and [month] in(2,3)
product month number
---------- ----------- -----------
aa 2 30
aa 3 60
(2 行受影响)
select a.* from tb a join tb b on a.product=b.product and a.number<>b.number and a.month in(2,3)