在SQL中过滤结果 [英] Filter Results in SQL
本文介绍了在SQL中过滤结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
假设我有一张桌子
id value
------ ---------
10 123
10 422
11 441
11 986
12 674
13 648
我需要一个查询,该查询将仅返回那些具有2个或更多与它们相关联的值的ID.因此,在这种情况下,它只会返回ID 10& 11,但我需要所有记录.
I need a query which will return only those id's which have 2 or more values associated with them. So, in that case it will only return ID 10 & 11, but i need al the records.
所以结果如下:
id value
------ ---------
10 123
10 422
11 441
11 986
谢谢.
推荐答案
select a2.*
from MyTable a2
inner join
(
select a1.id
from MyTable a1
group by a1.id
having count(*) > 1
) a3
on a3.id = a2.id
这篇关于在SQL中过滤结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文