Custom ORDER BY to ignore 'the'

后端 未结 7 2109
野趣味
野趣味 2020-12-09 11:00

I\'m trying to sort a list of titles, but currently there\'s a giant block of titles which start with \'The \'. I\'d like the \'The \' to be ignored, and the sort to work o

相关标签:
7条回答
  • 2020-12-09 11:34

    The best way to handle this would be to have a column that contains the value you want to use specifically for ordering output. Then you'd just have to use:

      SELECT t.title
        FROM MOVIES t
    ORDER BY t.order_title
    

    There are going to be various rules about what should and should not be used to order titles.

    Based on your example, an alternative would be to use something like:

       SELECT t.title
        FROM MOVIES t
    ORDER BY SUBSTR(t.title, INSTR(t.title, 'The '))
    

    You could use a CASE statement to contain the various rules.

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