我有一个表,它是这样形成的,SELECT *来自test,其中最大的(数字,首字母) | id | username | number | initial |
我需要添加顶号和头号来检索顶部。
以此为例
| id | username | number | initial | total
| 1 | a | 665 | 441 | 1106
| 2 | b | 918 | 99 | 1017
| 3 | c | 611 | 336 | 947
| 4 | d | 491 | 968 | 1459
| 5 | e | 414 | 129 | 543我需要的是首先检索最高的数字和最后的最低的数字。
我已经尝试过SELECT * FROM测试WHERE GREATEST(number, initial),但这似乎并不管用。
我不太熟悉SQL,但有一件事我已经尝试过了,那就是
发布于 2015-01-12 01:32:50
如果您想获得数字+初始值的最高值的记录:
select * from test
order by (number + initial) desc
limit 1或者,如果您希望所有的记录具有最大的数字+初始值:
select * from test
where test.number + test.initial =
(select max(test.number + test.initial)
from test)或者,如果要按数字+首字母的值按降序顺序排序所有记录:
select * from test
order by (number + initial) deschttps://stackoverflow.com/questions/27893925
复制相似问题