How to use substring in order by

后端 未结 2 1557
长发绾君心
长发绾君心 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: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);
    

提交回复
热议问题