为什么我无法通过此查询获得所需的订单?

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"}]}


php - SQL查询给我错误的顺序-LMLPHP

最佳答案

好吧,我现在开始工作了。感谢大家。

 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/

10-12 12:52