Order by FIELD in MYSQL

后端 未结 1 855
无人及你
无人及你 2020-11-30 12:47

I am struggling to resolve this . I have a table like this .

    +-------------+-------+
    | type        | COUNT |
    +-------------+-------+
    | A              


        
相关标签:
1条回答
  • how abt this:

    select a.col as type,coalesce (`COUNT`,0) as `count`
    from 
    (select 'A' as col union all
    select 'B' as col union all
    select 'C' as col union all
    select 'D' as col )a
    left join Table1 T
    on a.col=T.type
    order by FIELD(a.col,'A','B','C','D') ; 
    


    SQL fiddle demo

    0 讨论(0)
提交回复
热议问题