比如数据有
intID intUserNum
1 10
1 11
2 10
2 10
3 12
3 12
3 12
4 13
4 13
4 14请问怎么用select查找出intID为
1
4
的记录,条件是后面的intUserNum不同.
intID intUserNum
1 10
1 11
2 10
2 10
3 12
3 12
3 12
4 13
4 13
4 14请问怎么用select查找出intID为
1
4
的记录,条件是后面的intUserNum不同.
(intID int,
intUserNum int)
insert into #temp
select '1','10' union all select '1','11' union all select '2','10' union all select '2','10' union all select '3','12' union all select '3','12' union all select '3','12' union all select '4','13' union all select '4','13' union all select '4','14'
select * from #temp
select distinct intID from #temp a
where (select count(distinct intUserNum) from #temp where intID=a.intID)>1------------
1
4
group by id
having count(distinct intUserNum)>1
用wangdehao(找找找(现在很幸福)) 的简单多了
(intID int,
intUserNum int)
insert into #temp
select '1','10' union all select '1','11' union all select '2','10' union all select '2','10' union all select '3','12' union all select '3','12' union all select '3','12' union all select '4','13' union all select '4','13' union all select '4','14'
select intid from #temp group by intid having count(distinct intusernum)>1drop table #temp
select distinct * from where intID=1 or intID=4