MySQL 查询仅显示左侧 15 个单词?
mysqlmysqli database更新于 2024/8/13 19:24:17
为此,请在 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)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

