gpt4 book ai didi

mysql - 3 每个客户的最后记录

转载 作者:行者123 更新时间:2023-11-29 03:34:44 24 4
gpt4 key购买 nike

我有一张这样的客户和请求表:

客户表:

Key | Name
----+-----------
1 | Roberto
2 | Thiago
3 | Mike

请求表:

key | Date       | Customer
----+------------+------------
1 | 2012-02-07 | 1
2 | 2012-02-08 | 2
3 | 2012-02-09 | 1
4 | 2012-03-07 | 1
5 | 2012-03-08 | 3
6 | 2012-03-09 | 2
7 | 2012-04-07 | 3
8 | 2012-04-08 | 1
9 | 2012-04-09 | 3

我想要一个返回每个客户的最后 3 个请求的查询。Obs:我正在使用 MySQL 服务器

返回应该是这样的:

key | Date       | Customer
----+------------+-----------
1 | 2012-02-07 | 1
3 | 2012-02-09 | 1
4 | 2012-03-07 | 1
2 | 2012-02-08 | 2
6 | 2012-03-09 | 2
5 | 2012-03-08 | 3
7 | 2012-04-07 | 3
9 | 2012-04-09 | 3

我不能使用“TOP”命令,因为我使用的是 MySQL 服务器,而这个命令只能在 SQL Server 中使用。

最佳答案

我想这应该可行:

SELECT     req.Key,
req.date,
req.customer
FROM [dbo].[Requests] req
INNER JOIN [dbo].[Customers] cust ON cust.CustomerID = req.customerID
GROUP BY req.Key, req.date, req.customer
ORDER BY req.date

希望这有帮助!!!

关于mysql - 3 每个客户的最后记录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24148882/

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