[英]SQL query giving me wrong order
Why am i not getting the order i want with this query? 为什么我无法通过此查询获得所需的订单?
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
This query gives me a random order all the time when i input the t_rank. 当我输入t_rank时,此查询始终为我提供随机顺序。 It is not giving me a 1,2,3 order but instead it gives me random all the time.
它不是给我1,2,3的命令,而是一直给我随机的命令。 Can someone help me pls?
有人可以帮我吗?
Here is the result that is giving me 这是给我的结果
{"nresults":[{"e_name":"Musical Festival - Song Composition","First":"2nd",
"Second":"1st",
"Third":"3rd"}]}
Here is my expected output 这是我的预期输出
{"nresults":[{"e_name":"Musical Festival - Song Composition","First":"1st",
"Second":"2nd",
"Third":"3rd"}]}
Ok i got it working now. 好吧,我现在开始工作了。 Thanks everyone.
感谢大家。
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
i just move the order by clause after the end before the separator inside the group_concat 我只是将order by子句移到group_concat内部分隔符的末尾之后
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.