简体   繁体   中英

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. It is not giving me a 1,2,3 order but instead it gives me random all the time. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM