为什么我在这个查询中没有得到我想要的订单?
SELECT
e_name,
a_shortcut,
GROUP_CONCAT(case
when t_rank = 1 then a_shortcut
when t_rank = 2 then a_shortcut
when t_rank = 3 then a_shortcut
end separator ',') as group_con
FROM team
INNER JOIN event
ON team.EID = event.eid
WHERE e_type = 'nonsport'
GROUP BY event.eid ORDER BY t_rank
当我输入 t_rank 时,该查询始终给出随机顺序。它没有给我 1,2,3 的顺序,而是一直给我随机的。有人可以帮我吗?
这是给我的结果
{"nresults":[{"e_name":"Musical Festival - Song Composition","First":"2nd",
"Second":"1st",
"Third":"3rd"}]}
这是我的预期输出
{"nresults":[{"e_name":"Musical Festival - Song Composition","First":"1st",
"Second":"2nd",
"Third":"3rd"}]}
最佳答案
好的,我现在可以使用了。谢谢大家。
select
e_name,
a_shortcut,
GROUP_CONCAT(case
when t_rank = 1 then a_shortcut
when t_rank = 2 then a_shortcut
when t_rank = 3 then a_shortcut
end order by t_rank separator ',') as group_con
from
team inner join event on team.EID = event.eid Where e_type = 'nonsport'
group by event.eid
我只是将 order by 子句移到 group_concat 内分隔符之前的末尾
关于php - SQL 查询给出了错误的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42342008/