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 教师闺蜜祝福语简短