表test
与列compname version
和表Bugs
与bugid compname
以下输出的SQL查询?
数据列test
:
A 1.2
B 1.5
C 1.6
B 1.3
C 1.5
A 1.6
B 1.6
数据为Bugs
:
1 A
1 C
2 A
2 B
3 A
3 B
3 C
查询:
Output the compname where version=1.6 and affected by bugid=1 along with the first(min) version in which the component appeared
输出:
A 1.2
C 1.5
我使用这个查询,但可以在此进行得更快:
select compname,min(version) from test where compname IN (select compname from test where version='1.6' and compname IN (select compname from Bugs where bugid=1)) group by compname
为什么第二次加入? – 2010-11-03 19:58:28
否则,你只会得到所检索行的最小值,这些值只是匹配'bugid = 1 AND t.version ='1.6''的值。这样你可以获得所有可能的版本,并选择该集合的最小值。 – theazureshadow 2010-11-03 20:00:42
+1,很好。 – 2010-11-03 20:02:19