0

以下查询给了我一行,因为b.id已固定。我想要一个查询,我可以给出一组 id 并为每个 id 获取最小值行。

我想要的效果就像我将此查询包装在一个循环中,覆盖一组 id,并使用每个 id 执行查询,b.id = value但这将是(数十个?)数千个查询。


select top 1 a.id, b.id, a.time_point, b.time_point
from orientation_momentum a, orientation_momentum b
where a.id = '00820001001' and b.id = '00825001001'
order by calculatedValue() asc

这是在 sql-server 上,但如果可能的话,我更喜欢便携式解决方案。

4

1 回答 1

1

SQL Server 排名功能应该可以解决问题。

select * from (
select a.id, b.id, a.time_point, b.time_point, 
rank() over (partition by a.id, b.id
order by calculatedValue() asc) ranker
from orientation_momentum a, orientation_momentum b
where a.id = '00820001001' and b.id between 10 and 20
) Z where ranker = 1
于 2012-10-02T01:21:44.687 回答