Benefits Of Using SQL Ordinal Position Notation?

前端 未结 6 2090
夕颜
夕颜 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:15

    I tend to use in-line views now:

    select col_a, count(*) from
      (select case ...... end col_a from ...)
    group by col_a
    order by col_a;
    

    But in the days before they were valid syntax, it did help retyping the full text of the column. With tricky functions you had the potential for discrepancies between the value in the SELECT and ORDER BY such as

    select ltrim(col_name,'0123456789')
    from table
    order by ltrim(col_name,'123456789')
    

    The '0' in the SELECT means that you are not ordering by what you select.

提交回复
热议问题