只顯示從左側開始的 15 個單詞的 MySQL 查詢?


為此,請在 MySQL 中使用 LEFT。首先,讓我們建立一個表 −

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

使用 insert 命令在表中插入一些記錄 −

mysql> insert into DemoTable values('Java database connectivity to MySQL database');
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable values('Python with django framework');
Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable values('C with data structure and algorithm');
Query OK, 1 row affected (0.33 sec)

使用 select 語句從表中顯示所有記錄 −

mysql> select *from DemoTable;

這將生成以下輸出 −

+----------------------------------------------+
| Title                                        |
+----------------------------------------------+
| Java database connectivity to MySQL database |
| Python with django framework                 |
| C with data structure and algorithm          |
+----------------------------------------------+
3 rows in set (0.00 sec)

以下是在 MySQL 中僅顯示從左側開始的 15 個單詞的查詢 −

mysql> select left(Title,15) as Title from DemoTable;

這將生成以下輸出

+-----------------+
| Title           |
+-----------------+
| Java database c |
| Python with dja |
| C with data str |
+-----------------+
3 rows in set (0.00 sec)

更新於: 17-Dec-2019

60 瀏覽

開啟你的 職業

透過完成課程獲得認證

開始學習
廣告
© . All rights reserved.