码迷,mamicode.com
首页 > 数据库 > 详细

【MySQL】MySQL统计NULL字段处理

时间:2017-09-14 12:01:08      阅读:205      评论:0      收藏:0      [点我收藏+]

标签:workspace   join   welcome   ice   disk   desc   sele   use   rom   

select A.user_id,ifnull(sum(ifnull(A.ex_cpu,0)),0) AS a0, ifnull(sum(ifnull(A.ex_mem,0)),0) AS a1, ifnull(sum(ifnull(A.ex_disk,0)),0) AS a2, ifnull(sum(ifnull(B.cpu,0)),0) AS a3, ifnull(sum(ifnull(B.mem,0)),0) AS a4, ifnull(sum(ifnull(B.disk,0)),0) AS a5 from tbl_service_instance as A left join tbl_service_spec as B on A.service_spec_id = B.id where A.env_id ="84d97900-8d24-4904-984e-e49d6809e3af" and A.project_id ="6fe742d2-c872-4292-bb03-bf1af481cb4d " and A.status != 2 and A.status != 3 group by A.user_id;

select A.user_id, ifnull(sum(ifnull(A.ex_cpu,0)),0)+ifnull(sum(ifnull(B.cpu,0)),0) AS aaa, ifnull(sum(ifnull(A.ex_mem,0)),0)+ifnull(sum(ifnull(B.mem,0)),0) AS bbb, ifnull(sum(ifnull(A.ex_disk,0)),0)+ifnull(sum(ifnull(B.disk,0)),0) AS total from tbl_service_instance as A left join tbl_service_spec as B on A.service_spec_id = B.id where A.env_id = "84d97900-8d24-4904-984e-e49d6809e3af" and A.project_id = "6fe742d2-c872-4292-bb03-bf1af481cb4d" and A.status != 2 and A.status != 3 group by user_id ORDER BY total DESC LIMIT 5;

 

 

cd /opt/java/workspace/xproject && echo -e "\033[32mWarmly welcome, My honored master, I‘ll take full orders of you! \033[0m"

【MySQL】MySQL统计NULL字段处理

标签:workspace   join   welcome   ice   disk   desc   sele   use   rom   

原文地址:http://www.cnblogs.com/junneyang/p/7519603.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!