gpt4 book ai didi

mysql - 每位客户当天的倒数第五笔交易

转载 作者:行者123 更新时间:2023-11-29 23:15:52 25 4
gpt4 key购买 nike

我有一个包含信息的表格:

customer_id | Date | Time| Sales 

某一天我们有客户的多笔交易。如何检索每个客户在任意一天的倒数第五笔交易?

最佳答案

试试这个:

SELECT A.customer_id, A.Date, A.Time, A.Sales 
FROM (SELECT A.customer_id, A.Date, A.Time, A.Sales,
IF(@customerId = @customerId:=A.customer_id AND @Date = @Date:=A.Date, @Id:=@ID + 1, @ID:=1) AS RowNum
FROM tableA A, (SELECT @customerId:=0, @Date:='', @Id:=0) AS B
ORDER BY A.customer_id, A.Date, A.Time DESC
) AS A
WHERE A.RowNum = 5

关于mysql - 每位客户当天的倒数第五笔交易,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27816173/

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