我有一个使用子查询对数据进行子集化的查询,然后我尝试从子查询中选择特定数据。子查询是:
select top 10 Build_ID, Appscan_Definitive_High,
rank() over (order by Appscan_Definitive_High desc) as rankpct
from
(
select build_id, convert(int,appscan_definitive_high) as
appscan_definitive_high
from dbo.SDFBuildMetrics
where coalesce(appscan_definitive_high,0)>0
) a
,结果如下:
Build_ID Appscan_Definitive_High rankpct
31966 51 1
32627 51 1
44293 51 1
47011 51 1
47968 51 1
48554 51 1
25586 49 7
27370 49 7
40357 48 9
23867 44 10
但是当我针对子查询运行查询时:
select Appscan_Definitive_High
from
(
select top 10 Build_ID, Appscan_Definitive_High,
rank() over (order by Appscan_Definitive_High desc) as rankpct
from
(
select build_id, convert(int,appscan_definitive_high) as
appscan_definitive_high
from dbo.SDFBuildMetrics
where coalesce(appscan_definitive_high,0)>0
) a
) aa
我明白了:
Appscan_Definitive_High
1
44
21
44
2
44
2
6
7
7
完整查询的最终目的是检索min(AppScan_Definitive_High),但由于返回的值集与子查询返回的值集不匹配,min函数不能给我什么我需要。我假设子查询返回外部查询操作的一组数据,但在上例中似乎不是这种情况。
对此有何帮助?
答案 0 :(得分:4)
您没有按顺序运行选择前10名。要获得您想要的结果,您需要在那里订购。