Benefits Of Using SQL Ordinal Position Notation?

前端 未结 6 2091
夕颜
夕颜 2020-11-30 05:46

Background Information

Ordinal position notation, AKA ordinals, is column shorthand based on the column order in the list of columns in the SELECT cla

6条回答
  •  抹茶落季
    2020-11-30 06:08

    The two use cases for me are:

    • I am in a hurry and don't want to type, so I use the ordinal. I would always convert this to the column name for any non-temporary use
    • the column I am ordering by is a lengthy CASE statement; rather than retyping the CASE statement for the ORDER BY clause, I use the ordinal which keeps it DRY. There are ways around this, e.g., using CTEs, subqueries, or view, but I often find the ordinal is the simplest solution.

提交回复
热议问题