MySQL CASE语句或PHP if语句哪个更快?
与PHPif语句相比,MySQLCASE语句更快。PHPif语句花费太多时间,因为它加载数据然后处理,而CASE语句则不会。
让我们首先创建一个表并解决一个MySQLCASE语句的示例-
create table DemoTable (Value int);
使用插入命令在表中插入一些记录-
insert into DemoTable values(100); insert into DemoTable values(500); insert into DemoTable values(1000);
使用select语句显示表中的所有记录-
select *from DemoTable;
这将产生以下输出-
+-------+ | Value | +-------+ | 100 | | 500 | | 1000 | +-------+ 3 rows in set (0.00 sec)
以下是对MySQLCASE语句的查询-
select Value, case when Value > 500 THEN "It is greater than or equal to 1000" else "It is lower than 1000" end as comparison from DemoTable;
这将产生以下输出-
+-------+-------------------------------------+ | Value | comparison | +-------+-------------------------------------+ | 100 | It is lower than 1000 | | 500 | It is lower than 1000 | | 1000 | It is greater than or equal to 1000 | +-------+-------------------------------------+ 3 rows in set (0.00 sec)
热门推荐
10 对航母的祝福语简短
11 描写周末的祝福语简短
12 学生祝福语简短古诗大全
13 最美母女祝福语简短英文
14 友谊晚上祝福语大全简短
15 周日徒步祝福语大全简短
16 男友人新婚祝福语简短
17 回家长的祝福语简短
18 给姐妹乔迁祝福语简短