gpt4 book ai didi

mysql如何显示每个客户的最后2条记录

转载 作者:行者123 更新时间:2023-11-29 06:19:15 24 4
gpt4 key购买 nike

<分区>

我想根据日期显示每个客户的最后 2 条记录,例如:

      id   |   name   |   date
1 | a | 2015-10-11
2 | a | 2015-09-11
3 | b | 2015-10-10
4 | b | 2015-09-01

我试过

SELECT id,cust_id FROM ( SELECT id,cust_id @currcount := IF(@currvalue = cust_id, @currcount + 1, 1) AS cnt FROM customer ORDER BY id DESC) AS whatever WHERE cnt <= 2

但它显示所有记录

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