在 MySQL 中从左侧获取一些单词

mysqlmysqli database

为此,请在 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)

相关文章