Order multiple columns ASC

后端 未结 1 1910
温柔的废话
温柔的废话 2021-01-28 20:33

My database layout:

ID Description           Shop 1  Shop 2  Shop 3
1 | Article Description | 19.99 | 29.99 | 4.99
2 | Article Description | 45.94 | 14.54 | 87.5         


        
1条回答
  •  生来不讨喜
    2021-01-28 21:09

    I think its best to do it via PHP on the application layer , but you can do it with LEAST() and GREATEST() :

    SELECT t.id,t.description,
           LEAST(t.shop1,t.shop2,t.shop3) as lowest,
           (t.shop1+t.shop2+t.shop3) - (LEAST(t.shop1,t.shop2,t.shop3) + GREATEST(t.shop1,t.shop2,t.shop3)) as middle_one
           GREATEST(t.shop1,t.shop2,t.shop3) as biggest
    FROM YourTable t
    

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