让我们首先创建一个表-
mysql> create table DemoTable1612 -> ( -> FirstName varchar(20), -> LastName varchar(20) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1612 values('David','Brown'); mysql> insert into DemoTable1612 values('John','Smith'); mysql> insert into DemoTable1612 values('Bob','Taylor');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1612;
这将产生以下输出-
+-----------+----------+ | FirstName | LastName | +-----------+----------+ | David | Brown | | John | Smith | | Bob | Taylor | +-----------+----------+ 3 rows in set (0.00 sec)
以下是查询以获取MySQL中选定行的大小-
mysql> select sum(char_length(FirstName)) from DemoTable1612 where LastName IN('Brown','Smith','Taylor');
这将产生以下输出-
+-----------------------------+ | sum(char_length(FirstName)) | +-----------------------------+ | 12 | +-----------------------------+ 1 row in set (0.00 sec)