gpt4 book ai didi

mysql - 分组依据的前 2 个值

转载 作者:行者123 更新时间:2023-11-30 21:23:20 25 4
gpt4 key购买 nike

当我按详细信息列分组并查找日期“2009-08-05”时,我也想要较早的一天 ID。

select id,  details, abc_date from test order by details limit 10;
+------------+------------------+------------+
| id | details | abc_date |
+------------+------------------+------------+
| 2224 | 10025 | 2009-08-11 |
| 4575 | 10025 | 2009-09-02 |
| 1617 | 10025 | 2009-08-05 |
| 3614 | 10025 | 2009-08-24 |
| 1811 | 10025 | 2009-08-07 |
| 969 | 10025 | 2009-07-29 |
| 1441 | 10025 | 2009-08-03 |
| 4345 | 10025 | 2009-08-31 |
| 3330 | 10025 | 2009-08-21 |
| 799 | 10025 | 2009-07-27 |
+------------+------------------+------------+

最佳答案

SELECT  details,
(
SELECT id
FROM test ti
WHERE ti.details = to.details
ORDER BY
date
LIMIT 1
) AS first_id
FROM test to
GROUP BY
details

关于mysql - 分组依据的前 2 个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1637161/

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