我有一个mysql表(让我们称之为表格),在这里,我存储在游戏中得分。
| ID | SCORE |
|----|-------|
|1 |10 |
|2 |8 |
|3 |15 |
|4 |9 |我想知道的是,是否有一种简洁的方法可以让一行包含最后一个分数(带有
而最高的分数呢?
目前我正在做
SELECT
score AS last_score,
(SELECT MAX(score) FROM table) AS best_score
FROM table
ORDER BY id DESC
LIMIT 1这正好给了我我想要的
|last_score|best_score|
|----------|----------|
|9 |15 |但是就性能而言,我想知道最好不要有两个select:s
我更愿意做些事情
SELECT
score AS last_score,
MAX(score) AS best_score
FROM table
ORDER BY id DESC
LIMIT 1这给了我最好的分数,但不是最新的。
有什么建议吗?
发布于 2021-03-10 11:46:35
选择(按id desc限制1从采购订单中选择得分)为last_score,选择最大(得分)为max_score (从购买)为max_score
https://stackoverflow.com/questions/66563818
复制相似问题