只显示从左侧开始的 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)
广告