【发布时间】:2023-03-09 04:20:01
【问题描述】:
我有一个使用子查询对数据进行子集化的查询,然后我尝试从子查询中选择特定数据。子查询是:
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 函数不能满足我的需要。我假设子查询返回一组外部查询对其进行操作的数据,但在上面的示例中似乎并非如此。
有什么帮助吗?
【问题讨论】:
标签: sql-server tsql