gpt4 book ai didi

MYSQL - 选择最新的列类型条目

转载 作者:行者123 更新时间:2023-11-29 04:51:35 24 4
gpt4 key购买 nike

我有一个包含列的表格:
s_Id (primary int), sup_type (int), sup_date (datetime), sup_req (int)

到目前为止,sup_type 中的值介于 0-5 之间。

如何提取每个 sup_type (0-5) 的最新条目(按 sup_date)。

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* s_Id * sup_type * sup_date * sup_req *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 1 * 0 * 2012-06-15 10:13:21 * 4 *
* 2 * 0 * 2012-06-15 11:22:01 * 4 *
* 3 * 1 * 2012-06-15 13:23:32 * 4 *
* 4 * 2 * 2012-06-16 08:04:29 * 4 *
* 5 * 1 * 2012-06-16 16:23:24 * 4 *
* 6 * 1 * 2012-06-17 13:14:05 * 4 *
* 7 * 3 * 2012-06-18 13:37:55 * 4 *
* 8 * 4 * 2012-06-19 13:21:52 * 4 *
* 9 * 4 * 2012-06-20 16:15:19 * 4 *
* 10 * 5 * 2012-06-20 16:17:37 * 4 *
* 11 * 0 * 2012-06-20 16:21:53 * 4 *
* 12 * 1 * 2012-06-20 16:28:13 * 4 *
* 13 * 3 * 2012-06-21 12:23:29 * 4 *
* 14 * 3 * 2012-06-22 07:26:41 * 4 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

我要提取

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* s_Id * sup_type * sup_date * sup_req *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* 4 * 2 * 2012-06-16 08:04:29 * 4 *
* 9 * 4 * 2012-06-20 16:15:19 * 4 *
* 10 * 5 * 2012-06-20 16:17:37 * 4 *
* 11 * 0 * 2012-06-20 16:21:53 * 4 *
* 12 * 1 * 2012-06-20 16:28:13 * 4 *
* 14 * 3 * 2012-06-22 07:26:41 * 4 *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *

谢谢。

最佳答案

SELECT
b.*
FROM
(
SELECT sup_type, MAX(sup_date) AS maxsupdate
FROM tbl
GROUP BY sup_type
) a
INNER JOIN
tbl b ON
a.sup_type = b.sup_type AND
a.maxsupdate = b.sup_date
ORDER BY
b.s_Id

关于MYSQL - 选择最新的列类型条目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11167540/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com