How to use substring in order by

后端 未结 2 1539
长发绾君心
长发绾君心 2021-01-28 21:34

I have the following query to select the domain names that have three levels separated by two dots:

select domainname from db.table
where criteria like (\'*.com\         


        
相关标签:
2条回答
  • 2021-01-28 21:45

    You could use the function SUBSTRING_INDEX

    ORDER BY SUBSTRING_INDEX(domainname, '.', -2)
    
    0 讨论(0)
  • 2021-01-28 21:54

    Check out the SUBSTRING_INDEX() function:

    select domainname from db.table
    where criteria like ('*.com')
    AND domainname like ('%.%.%')
    ORDER BY SUBSTRING_INDEX(domainname, '.', -2);
    
    0 讨论(0)
提交回复
热议问题