sql server 查询出现部分错误

肥猫_joe
  • 65
select t1.mk,t2.gnjy,t1.rjcw,t3.total,count(t1.rjcw)/(t3.total*1.0) percentage
from (select mk,count(cswhdxs) as rjcw from YSDP_DATA where YEAR(TJSJ)=2015 and CSWHDXS='软件错误' group by mk) t1 left join
     (select mk,count(cswhdxs) as gnjy from YSDP_DATA where YEAR(TJSJ)=2015 and CSWHDXS='功能建议' group by mk) t2 
      on t1.mk=t2.mk left join
     (SELECT mk,count(cswhdxs) AS total FROM YSDP_DATA where year(TJSJ)=2015 group by MK) t3
      on t1.mk=t3.mk
group by t1.MK,t1.rjcw,t2.gnjy ,t3.total
 

查询语句如上,目的很简单,就是统计表中字段CSWHDXS中(特定年份)软件错误 和 功能建议 的数量并算出 软件错误 在该列的占比,最后用另一字段mk进行分类。
现在前4列应该都没有问题,最后一列计算却有明显错误,结果如下图

图片描述

最后一列明显计算错误,求教大家原因在哪里,应该如何修改。或者是我的思路根本不对。

回复
阅读 2.2k
1 个回答
✓ 已被采纳

    count(t1.rjcw)/(t3.total*1.0) percentage
    改成
    t1.rjcw/(t3.total*1.0) percentage
宣传栏