[英]SQL: select multiple columns based on multiple groups of minimum values?
以下查詢給了我一行,因為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上,但如果可能的話,我希望使用便攜式解決方案。
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
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.