获取 MySQL 中特定列值的大小并显示和
我们首先创建一个表 −
mysql> create table DemoTable1612 -> ( -> FirstName varchar(20), -> LastName varchar(20) -> ); Query OK, 0 rows affected (0.87 sec)
使用 insert 命令向表中插入一些记录 −
mysql> insert into DemoTable1612 values('David','Brown'); Query OK, 1 row affected (0.75 sec) mysql> insert into DemoTable1612 values('John','Smith'); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable1612 values('Bob','Taylor'); Query OK, 1 row affected (0.13 sec)
使用 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)
广告