Mysql MAX值和Last Record同时出现

时间:2012-11-16 16:30:40

标签: mysql

如果你有2个字段的表:

ID | AMOUNT

如何使用1个查询获得最大值(AMOUNT)和最后输入记录的数量(按ID desc排序)?

感谢你

2 个答案:

答案 0 :(得分:1)

select amount as last_amount, 
      (select max(amount) from your_table) as max_amount
from your_table
order by id desc
limit 1

答案 1 :(得分:0)

你可以这样做:

SELECT
    (SELECT MAX(amount) FROM table) as Max,
    (SELECT amount FROM table ORDER BY id DESC LIMIT 1) as Last