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 生日广州男生祝福语简短