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 次瀏覽

開啟你的 職業生涯

透過完成課程獲得認證

開始吧
廣告
© . All rights reserved.