我有一个查询,它使用子查询对数据进行子集,然后尝试从子查询中选择特定的数据。子查询是:
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函数没有给我所需的。我假设子查询返回外部查询所针对的一组数据,但在上面的示例中似乎并非如此。
对此有什么帮助吗?
发布于 2015-02-10 15:15:21
您正在运行,选择前10位,没有订单。为了得到你想要的结果,你需要在那里有秩序。
https://stackoverflow.com/questions/28435107
复制相似问题