ORDER BY Alias not working

后端 未结 6 1665
执笔经年
执笔经年 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:05

    The reason for this can be found in the documentation:

    Each expression [in the ORDER BY list] can be the name or ordinal number of an output column (SELECT list item), or it can be an arbitrary expression formed from input-column values.

    (my emphasis)

    The reason for this is that old versions of the SQL standard (SQL-92) only allowed sorting by output column name or number, whereas newer versions allow sorting by arbitrary expressions, but those expressions are formed from input column values.

    Other answers already contain various suitable workarounds for your case.

提交回复
热议问题