![](/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.