ORDER BY Alias not working

后端 未结 6 1677
执笔经年
执笔经年 2020-12-06 13:39

UPDATING QUESTION:

ERROR:  column \"Fruits\" does not exist

Running Postgres 7.4(Yeah we are upgrading)

Why can\'t I ORDER BY the

6条回答
  •  不知归路
    2020-12-06 14:15

    You can use ORDER BY 1 to order by the first field, which is "Fruits". The same is valid for GROUP BY

    Update

    For the order, instead of doing the case in the order by, create a new column in.. say.. the second position:

    (CASE 
        WHEN "Fruits" = 'Apple' THEN 1 
        WHEN "Fruits" = 'Pear' THEN 2 
        WHEN "Fruits" = 'Grapes' THEN 3 
        ELSE 4 ) as Order
    

    Then in you ORDER BY 2.

提交回复
热议问题