如何在MySQL上选择此结果的最后一个值:
这是查询的结果:
SELECT * from transaction WHERE transaction_id = 2
我只需要最后一个值3 300 2
bank_id amount transaction_id
1 800 2
3 50 2
3 300 2
答案 0 :(得分:1)
SELECT *
FROM transaction
WHERE transaction_id = 2
ORDER BY bank_id desc
LIMIT 1
答案 1 :(得分:1)
如果bank_id
不是唯一的,并且您想首先选择最高金额的记录,您可以试试这个:
SELECT *
FROM transaction
WHERE transaction_id = 2
ORDER BY bank_id DESC
, amount DESC
LIMIT 1
答案 2 :(得分:-1)
尝试这个..
SELECT *
FROM transaction
WHERE transaction_id = 2
ORDER BY transaction_id DESC
LIMIT 1