從 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 中獲取一些單詞的查詢 −

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

這將產生以下輸出 −

+-----------------+
| Title           |
+-----------------+
| Java datab      |
| Python wit      |
| C with dat      |
+-----------------+
3 rows in set (0.00 sec)

更新於: 12-Dec-2019

88 瀏覽

開始你的 職業生涯

透過完成課程來獲得認證

開始
廣告
© . All rights reserved.