bitsCN.com
decode与case when的区别
求和:sum(decode(sign(xingji - 6),'',h.real_count,1,h.real_count,0))
decode相较于case when,函数里面不能使用and连接多个条件,只能使用函数嵌套
例如:sum(decode(sign(xingji - 6),-1,decode(hh.quxian,18,h.real_count,19,h.real_count,20,h.real_count,24,h.real_count,
34,h.real_count,35,h.real_count,0),0))
求和:sum(case when start_time = '24' then quantity else 0 end)
case when显得有些臃肿,但是在多个条件连接时比较方便,例如:sum(case when
start_time = '24' and city_code = '010' then quantity else 0 end)
另说明:sum()函数用于求和,sign()函数用于返回参数是大于0,还是小于0或者等于0,
一个例外是返回空:'';
例如:sign(1)--->1,sign(-1)--->-1,sign(0)--->0,sign(null)--->'';
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号