具体SQL如下,表名table,查询列名Age varchar2类型 有什么区别呢 数据量百万时哪个运行效率快一点
select
count(decode(t.Age,'20',1,null) ) as Age等于20数量count,
sum(decode(t.Age,'20',1,null)) as Age等于20数量sum,
count(case when t.Age='20' then 1 else 0 end) as Age等于20的数量casecount,
sum(case when t.Age='20' then 1 else 0 end) as Age等于20的数量casesum
from table t;
本文通过一个具体的SQL案例,对比了使用DECODE函数与CASE语句进行条件计数的不同实现方式,并探讨了这两种方法在大数据量下的性能差异。
973

被折叠的 条评论
为什么被折叠?



