MySQL 中包含“The”的文本字符串操作


可以使用 ORDER BY TRIM()。我们首先创建一个表 -

mysql> create table DemoTable
   -> (
   -> Title text
   -> );
Query OK, 0 rows affected (1.09 sec)

使用插入命令在表中插入一些记录 -

mysql> insert into DemoTable values('MongoDB is a no SQL database');
Query OK, 1 row affected (0.18 sec)
mysql> insert into DemoTable values('The MySQL is a relational database');
Query OK, 1 row affected (0.22 sec)
mysql> insert into DemoTable values('The Java language is good');
Query OK, 1 row affected (0.35 sec)
mysql> insert into DemoTable values('Python is good language');
Query OK, 1 row affected (0.17 sec)

使用 select 语句显示表中的所有记录 -

mysql> select *from DemoTable;

这将产生以下输出 -

+----------------------------------+
| Title                            |
+----------------------------------+
| MongoDB is a no SQL database     |
|The MySQL is a relational database|
| The Java language is good        |
| Python is good language          |
+----------------------------------+
4 rows in set (0.00 sec)

以下是包含“The ”的文本字符串操作的查询 -

mysql> select *from DemoTable
   -> order by trim(leading 'The ' from Title);

这将产生以下输出 -

+----------------------------------+
| Title                            |
+----------------------------------+
| The Java language is good        |
| MongoDB is a no SQL database     |
|The MySQL is a relational database|
| Python is good language          |
+----------------------------------+
4 rows in set (0.00 sec)

更新时间: 17-Dec-2019

132 次浏览

开启你的 职业生涯

通过完成课程获得认证

开始吧
广告