MySQL-仅返回具有相同唯一ID的第一行

时间:2020-07-16 16:44:41

标签: mysql sql database subquery greatest-n-per-group

请考虑下表:

enter image description here

如图所示,我只想从第一个不同的ID返回所有数据。如何在MySQL中实现?

2 个答案:

答案 0 :(得分:1)

您可以使用子查询进行过滤。假设 first 首先是指带有较早start_time的行,则为:

select t.*
from mytable t
where t.start_time = (
    select min(t1.start_time) from mytable t1 where t1.call_unique_id = t.call_unique_id
)

答案 1 :(得分:1)

from your_table t1
join
(
  select min(call_unique_id) as id
  from your_table
  group by start_time
) t2 on t1.id = t2.id

group by也应该做。所以尝试

select * from your_table group by call_unique_id 
相关问题