简单的SQL数据求百分率不对 --郁闷
各位:
我SQL统计数据表t_injPOhis(系统是客户设计的,injQty未完成就为null)分组产品、日期数据:计划数量(int类型)、完成数量(int类型)、差额、完成率
出现完成率总是1或0请情况,但完成数 和 计划数量都是对的:
Select pno,planDate,SUM(planQty) [planQty],SUM(Isnull(injQty,0)) [injQty],
SUM(planQty-Isnull(injQty,0)) [DiffQty],
SUM(Isnull(injQty,0))/SUM(planQty) [injRate]
From t_injPOhis
WHERE planDate between '2013-7-1' AND '2013-7-31'
Group By pno,planDate
运行结果:
J001RJ80061012013-07-01 00:00:00450004320018000
J001SJ80F54022013-07-01 00:00:00450004320018000
J4J9PG0033G022013-07-01 00:00:00200001632236780
S3027S00D16012013-07-01 00:00:008000800001
S6118S0033G022013-07-01 00:00:0014001320800
数据百分率不对
[解决办法]
SELECT pno ,
planDate ,
SUM(planQty) [planQty] ,
SUM(ISNULL(injQty, 0)) [injQty] ,
SUM(planQty - ISNULL(injQty, 0)) [DiffQty] ,
SUM(ISNULL(injQty, 0))*1.00 / SUM(planQty) [injRate] --这里修改一下,隐式转换了
FROM t_injPOhis
WHERE planDate BETWEEN '2013-7-1' AND '2013-7-31'
GROUP BY pno ,
planDate