我为每笔交易添加新记录(例如,小额信贷,今天客户支付300,然后插入新记录,明天500再次插入新记录)我如何根据客户id获得最后3条记录。
发布于 2014-02-01 19:15:52
SELECT Id
,Password
,Amount
,@curRow := @curRow + 1 AS row_number
FROM sample JOIN (SELECT @curRow := 0) r
where id=1
order by Row_number
desc limit 3;Working Fiddle
发布于 2014-02-01 18:04:23
SELECT * FROM table ORDER BY id DESC LIMIT 3;首先,使用ORDER BY对选择的内容进行排序,然后使用LIMIT获取第一条记录。
发布于 2014-02-01 18:05:15
您可以使用order by desc客户id并使用limit 0,3获取最后3条记录
select * from tbname
order by customerid desc
limit 0,3https://stackoverflow.com/questions/21496604
复制相似问题