Ordered Value by Column / Row

后端 未结 4 971
借酒劲吻你
借酒劲吻你 2021-01-16 15:24

Its a little difficult to explain. It might be easier to skip to the examples.

A table has an id and four columns that each allow null.

ID, Col1, Co         


        
4条回答
  •  难免孤独
    2021-01-16 15:57

    select value from (    
        select col1 as value from table_name where col1 is not null
         union
        select col2 as value from table_name where col2 is not null
         union
        select col3 as value from table_name where col3 is not null
         union
        select col4 as value from table_name where col4 is not null     
    ) order by value
    

提交回复
热议问题