我有以下MySQL查询,它可以按预期工作。
SELECT DISTINCT u.id,
CASE WHEN a.result IS NULL THEN 0 ELSE a.result END 'result',
RANK() OVER(ORDER BY result DESC) as 'rank'
FROM wp_users u, wp_usermeta um,
(SELECT pm.meta_value, COUNT(*) result
FROM wp_postmeta pm, wp_posts p
where p.id = pm.post_id
and p.post_status = 'publish'
and pm.meta_key = 'wpcf-userid'
and pm.post_id in (select pm1.post_id from wp_postmeta pm1 where pm1.meta_key = 'wpcf-badge-name' and pm1.meta_value = 'LD' and pm1.post_id = pm.post_id)
and pm.meta_value IN (select um.user_id FROM wp_usermeta um WHERE um.meta_value = 'VIC' and um.meta_key = 'wpcf-address-state')
GROUP BY pm.meta_value) a
WHERE u.id = um.user_id and a.meta_value = u.id
group by u.id
上面的结果是
Id|结果|排名
-|-|
2629|5|1
2783|5|2
817|4|3
2509|4|3
5363|3|5
我想要在任何领带的排名之前添加“T”字符串,如下所示:
Id|结果|排名
-|-|
2629|5|1
2783|5|2
817|4|T3
2509|4|T3
5363|3|5
有什么建议吗?
1条答案
按热度按时间t98cgbkg1#
我们可以子查询,然后使用
COUNT()
作为分析函数来检测排名中的平局: