sql 按表分组然后对其进行排序。

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了sql 按表分组然后对其进行排序。相关的知识,希望对你有一定的参考价值。

SELECT sa.*, s.*
FROM shipment_activities sa
JOIN shipments s ON s.id = sa.shipment_id
INNER JOIN
(
    SELECT max(date_time) maxTime, shipment_id, status_description
    FROM shipment_activities 
    GROUP BY shipment_id
) sa2
  ON sa.shipment_id = sa2.shipment_id
  WHERE sa.date_time = sa2.maxTime AND
  sa.status_description != 'Delivered'
  GROUP BY sa.shipment_id
  ORDER BY sa.shipment_id ASC

以上是关于sql 按表分组然后对其进行排序。的主要内容,如果未能解决你的问题,请参考以下文章

sql语句 按一列分组 然后再按别一列组内排序?

Spark 分组然后排序(Java 代码)

如何按列值的计数进行分组并对其进行排序?

sql 分组排序

mySQL分组排序

Mysql 分组并排序