使用MySQL SELECT进行简单的BOOLEAN评估?
您可以为此使用CASE语句。让我们看一个例子-
mysql> create table BooleanEvaluationDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> FirstValue int, -> SecondValue int -> );
使用insert命令在表中插入一些记录。查询如下-
mysql> insert into BooleanEvaluationDemo(FirstValue,SecondValue) values(10,5); mysql> insert into BooleanEvaluationDemo(FirstValue,SecondValue) values(15,20); mysql> insert into BooleanEvaluationDemo(FirstValue,SecondValue) values(50,40); mysql> insert into BooleanEvaluationDemo(FirstValue,SecondValue) values(500,1000);
使用select语句显示表中的所有记录。查询如下-
mysql> select *from BooleanEvaluationDemo;
这是输出-
+----+------------+-------------+ | Id | FirstValue | SecondValue | +----+------------+-------------+ | 1 | 10 | 5 | | 2 | 15 | 20 | | 3 | 50 | 40 | | 4 | 500 | 1000 | +----+------------+-------------+ 4 rows in set (0.00 sec)
以下是用于简单BOOLEAN评估的SELECT查询-
mysql> SELECT FirstValue,SecondValue,CASE WHEN FirstValue > SecondValue THEN 'true' ELSE 'false' END AS FirstValuesGreaterThanSecond from BooleanEvaluationDemo;
这是输出-
+------------+-------------+-------------------------------+ | FirstValue | SecondValue | FirstValuesGreaterThanSecond | +------------+-------------+-------------------------------+ | 10 | 5 | true | | 15 | 20 | false | | 50 | 40 | true | | 500 | 1000 | false | +------------+-------------+-------------------------------+ 4 rows in set (0.00 sec)
热门推荐
10 对患者生日祝福语简短
11 结婚祝福语简短装备
12 周岁祝福语学生文案简短
13 订婚领证祝福语简短精辟
14 导师获奖祝福语大全简短
15 新婚购房祝福语简短精辟
16 牛年祝福语简短的爱人
17 送芒果的祝福语简短
18 送给学长毕业祝福语简短