【问题标题】:Mysql - Return only first row having the same unique idsMysql - 仅返回具有相同唯一 ID 的第一行
【发布时间】:2020-11-06 09:44:48
【问题描述】:

考虑下表:

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

【问题讨论】:

  • 您的表格中似乎没有任何东西被称为“id”,所以这个问题很不清楚。图像也不清楚。将问题中的数据作为文本表
  • 您实际上尝试过什么但失败了?

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


【解决方案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
)

【讨论】:

    【解决方案2】:
    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 
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-05-11
      • 2019-06-11
      • 2018-07-28
      • 1970-01-01
      • 2012-12-06
      相关资源
      最近更新 更多