为此,请在MySQL中使用LEFT。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> Title text -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('Java database connectivity to MySQL database'); mysql> insert into DemoTable values('Python with django framework'); mysql> insert into DemoTable values('C with data structure and algorithm');
使用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)