SQL 按 "IF" 排序

SQL ORDER BY "IF"

如果列不包含数字,我想按标题排序;如果第一个字母是数字,我想按标题*1 排序。

ORDER BY if(title REGEXP '^[0-9]+'=0,title,title*1) ASC

什么是假的?

你先要哪个?数字还是字母?

您的方法的问题在于类型。所以,先决定你想要哪一个。 . .说出数字:

order by (title REGEXP '^[0-9]+') DESC,  -- put numbers first
         title + 0,                      -- order by numbers as numbers
         title                           -- order by everything else