php - SQL 查询给出了错误的顺序

标签 php mysql

为什么我在这个查询中没有得到我想要的订单?

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

enter image description here

最佳答案

好的,我现在可以使用了。谢谢大家。

 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/

相关文章:

Java与mysql通信

php - Uncaught SyntaxError : Unexpected identifier with php

php - 每个卖家的邮政编码过滤器 - mysql

mysql - Node.js 在循环中与 MySQL 链接 promise

mysql - 加入删除

php - 如何将ajax添加到wordpress主题

php - SOAP 服务器未获取所有参数

php - 在 WooCommerce "Order received"谢谢页面上获取订单 ID

6 月的 PHP strtotime 返回 7 月

mysql - 在 MySQL Loopback Connector 上执行原始查询