如何在MySQL CASE表达式中使用“ OR”条件?
在MySQLCASE表达式中设置相同的条件,例如“OR”。让我们首先创建一个样本表。
以下是查询
mysql> create table caseOrConditionDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(100), -> Score int -> );
以下是使用insert命令在表中插入一些记录的查询:
mysql> insert into caseOrConditionDemo(Name,Score) values('Larry',85);
mysql> insert into caseOrConditionDemo(Name,Score) values('Sam',74);
mysql> insert into caseOrConditionDemo(Name,Score) values('Mike',76);
mysql> insert into caseOrConditionDemo(Name,Score) values('Carol',65);以下是使用select命令显示表中记录的查询:
mysql> select *from caseOrConditionDemo;
这将产生以下输出
+----+-------+-------+ | Id | Name | Score | +----+-------+-------+ | 1 | Larry | 85 | | 2 | Sam | 74 | | 3 | Mike | 76 | | 4 | Carol | 65 | +----+-------+-------+ 4 rows in set (0.00 sec)
以下是在MySQLCASE表达式中使用类似“OR”的条件的查询:
mysql> select Id,Name,Score, -> case when Score > 75 then 'Better Score' -> when Score > 70 then 'Good Score' -> else 'Not Good Score' -> end as 'Performance' -> from caseOrConditionDemo;
这将产生以下输出
+----+-------+-------+----------------+ | Id | Name | Score | Performance | +----+-------+-------+----------------+ | 1 | Larry | 85 | Better Score | | 2 | Sam | 74 | Good Score | | 3 | Mike | 76 | Better Score | | 4 | Carol | 65 | Not Good Score | +----+-------+-------+----------------+ 4 rows in set (0.04 sec)
热门推荐
1 带狗狗训练
4 听力训练狗狗
6 怎训练狗狗
7 腹肌训练狗狗
8 网球训练狗狗
9 记叙文训练狗狗
10 狗狗太凶怎么训练
11 核心力量训练狗狗
12 狗狗乱叫怎么训练
13 发音训练狗狗
14 怎么训练狗狗叼东西给主人
15 荆州训练狗狗
16 篮球训练狗狗
17 做训练狗狗
18 训练狗狗坐姿