表数据
group by 取每组最大时间的值

第一种:

SELECT * FROM (SELECT * FROM clinic HAVING 1 ORDER BY created_time DESC) c GROUP BY c.unified_social_credit_code

注意: having 1 不能少, 不知道原理, 或者 在 order by 后面加 limit 100000 也可以

第二种

SELECT * FROM clinic c WHERE c.id IN (SELECT SUBSTRING_INDEX(GROUP_CONCAT(id ORDER BY created_time DESC), ‘,’, 1) FROM clinic GROUP BY unified_social_credit_code)

亲测可行;


第三种(失败)

SELECT * FROM clinic c GROUP BY c.unified_social_credit_code HAVING c.created_time = MAX(c.created_time)

得到结果
group by 取每组最大时间的值
group by 取每组最大时间的值
求解释下,什么原因呢

相关文章:

  • 2021-07-18
  • 2022-12-23
  • 2022-12-23
  • 2021-11-19
  • 2021-12-15
  • 2021-08-15
猜你喜欢
  • 2021-10-05
  • 2021-12-02
  • 2022-01-31
  • 2021-10-12
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案