mysql末字母排序,MySQL按字母顺序排序,但忽略“ The”

I have MySQL database that has a table with book data in it. One of the columns in the table is called "title". Some of the titles begin the word "the" and some do not.

Example:

"The Book Title One"

"Book Title Two"

"Book Title Three"

I need to pull these out of the database in alphabetical order, but I need to ignore the "the" in the beginning of the titles that start with it.

Does SQL (specifically MySQL) provide a way to do this in the query?

解决方案

do a case when to check if the column value starts with the and if it does, return the title without the 'The'. This will be a new column that you will be using later on for the sort order

select title, case when title like 'The %' then trim(substr(title from 4)) else title end as title2 from tablename order by title2;

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值