先来一个简单的sum
这样就会统计出所有product的qty.
但是很不幸,我们的系统里面居然有qty为负值。而我只想统计那些正值的qty,加上if function就可以了。 SQL为:
意思是如果qty > 0, 将qty的值累加到total_qty, 否则将0累加到total_qty.
再加强一点:
这样就可以统计有多少条负值的记录了。方便程序用来告诉人们这条记录数据异常
先来一个简单的sum
这样就会统计出所有product的qty.
但是很不幸,我们的系统里面居然有qty为负值。而我只想统计那些正值的qty,加上if function就可以了。 SQL为:
意思是如果qty > 0, 将qty的值累加到total_qty, 否则将0累加到total_qty.
再加强一点:
这样就可以统计有多少条负值的记录了。方便程序用来告诉人们这条记录数据异常
上一篇:创建显示桌面快捷图标
下一篇:mysql 删除多表数据
Linux 文件管理命令md5sum:MD5 函数值计算和检查 awk:模式匹配语言
java解决if else过多的问题
大家好,我是知数堂SQL 优化班老师 网名:骑龟的兔子今天给大家带来的 在MySQL,Oracle 都通用的一个非常基础的但是非常重要的函数case when我们看下如下表和数据 在这里我们通过case when 语句 制造一个列如下 这样我们就写了一个最基本的case when 语句。下面的链接是官方文档https://dev.mysql.com/doc/refman/8
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M