要计算超过三个列值的位置,可以使用WHERE子句。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> isMarried boolean, -> isActive boolean, -> isMember boolean, -> isOn boolean -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(true,false,true,false); mysql> insert into DemoTable values(false,false,false,false); mysql> insert into DemoTable values(true,true,true,true); mysql> insert into DemoTable values(true,false,false,true);
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+-----------+----------+-----------+------+ | isMarried | isActive | isMember | isOn | +-----------+----------+-----------+------+ | 1 | 0 | 1 | 0 | | 0 | 0 | 0 | 0 | | 1 | 1 | 1 | 1 | | 1 | 0 | 0 | 1 | +-----------+----------+-----------+------+ 4 rows in set (0.00 sec)
以下是查询以计算超过三个列值的情况-
mysql> select *from DemoTable where isMarried+isActive+isMember+isOn >=3;
输出结果
+-----------+----------+-----------+------+ | isMarried | isActive | isMember | isOn | +-----------+----------+-----------+------+ | 1 | 1 | 1 | 1 | +-----------+----------+-----------+------+ 1 row in set (0.00 sec)