SQL: ORDER BY using a substring within a specific column… possible?

前端 未结 7 714
清酒与你
清酒与你 2020-11-30 12:02

I have a database whose columns are npID, title, URL, and issue.

Here is an example of two years\' entries:

npID               title               UR         


        
相关标签:
7条回答
  • 2020-11-30 12:35

    Yes, you can use if/then constructions anywhere in a sql command.

    Do you already have a substring-pattern that works for you? if so, you can use something like:

    ORDER BY (IF (SUBSTRING(first_match_of_issue) IS NOT NULL) THEN first_match_of_issue ELSE second_match_of_issue))
    

    However - if you already know what they're going to be, then the CASE statements mentioned in other answers are probably easier.

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