我目前有下表:
Name | key | State
User 1 | 12 | 15
User 2 | 12 | 100
User 3 | 144 | 35
User 1 | 66 | 21
User 1 | 72 | 25
User 3 | 12 | 22
User 2 | 12 | 50
我想找到用户然后获取其最大状态编号,并从最高值排序最大值,其中列密钥= 12。
反映的结果就是这个。
Name | key | State
User 2 | 12 | 100
User 3 | 12 | 22
User 1 | 12 | 15
我自己无法解决这个问题,这就是为什么我需要帮助,对不起,虽然
答案 0 :(得分:2)
这是解决方案。
bool
答案 1 :(得分:0)
这是一个解决方案:
SELECT
Name
,Key
,MAX(State) AS State
FROM your_table
WHERE Key = 12
GROUP BY Name, Key
ORDER BY State DESC
答案 2 :(得分:0)
SELECT Name, key, MAX(State) as State
FROM <tabe>
WHERE
key = 12
GROUP BY Name, key
ORDER BY State DESC