![](/img/trans.png)
[英]In SQL how to compare values in two rows in the same table and find the highest value and then select its the entire row
[英]Can SQL Compare rows in same table , and dynamic select value?
如果有多行並且導師或位置不匹配,您似乎想要每個客戶的最短時間, null
值。
您可以使用 window 函數:
select customer, starttime,
(case when min(location) = max(location) then min(location) end) as location,
(case when min(tutor) = max(tutor) then min(tutor) end) as tutor
from (select t.*, rank() over (partition by customer order by starttime) as seqnum
from t
) t
where seqnum = 1
group by customer, starttime
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.