【发布时间】:2016-12-17 10:43:53
【问题描述】:
我需要为 TC5 而不是 id 分配等级。
SELECT a.id, a.user_id, a.tc1, a.tc4, min(a.tc5), a.tc2, b.avatar, c.username, @curRank := @curRank + 1 AS Rank
FROM
treningove_casy a INNER JOIN
sn_users b ON a.user_id=b.id INNER JOIN
users c ON a.user_id=c.id , (SELECT @curRank := 0) r
WHERE a.tc2 LIKE 'Motokáry Modrice'
GROUP BY a.user_id
那画面怎么样。请帮忙
修改后的代码
SELECT x.*, (@curRank := @curRank + 1) as Rank
FROM (SELECT a.id, a.user_id, a.tc1, a.tc4, min(a.tc5) as tc5,
a.tc2, b.avatar, c.username,
FROM sbhgl_chronoengine_chronoforms_datatable_treningove_casy a INNER JOIN
sbhgl_jsn_users b
ON a.user_id = b.id INNER JOIN
sbhgl_users c
ON a.user_id = c.id
WHERE a.tc2 LIKE 'Motokáry Modřice'
GROUP BY a.user_id
) x CROSS JOIN
(SELECT @curRank := 0) params
ORDER BY tc5 DESC;
【问题讨论】:
-
您需要使用
ORDER BY tc5。 -
您的查询有问题,因为您在使用
GROUP BY时选择了非聚合列。