这样的取值,为什么只能取整数,不能输出小数!

laodiao 2002-08-25 08:21:23
select sum(case if_passed when 1 then 1 else 0 end)/sum(case if_pass when 1 then 1 else 0 end)
from VWProduceOrders
使用两个Sum的比值,因为他输出的是小数,但是结构却是0,,怎么样才能取道小数值呢,
...全文
42 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
j9988 2002-08-25
  • 打赏
  • 举报
回复
SORRY!
supsuccess 2002-08-25
  • 打赏
  • 举报
回复
j9988(j9988)大侠误会了,我问的是楼主!
是谁除谁
j9988 2002-08-25
  • 打赏
  • 举报
回复
是: select 10.00/20
supsuccess 2002-08-25
  • 打赏
  • 举报
回复
不会吧?
应该是什么?(如:10/20)
j9988 2002-08-25
  • 打赏
  • 举报
回复
我觉得这样也行,你试一下:
select sum(case if_passed when 1 then 1.00 else 0.00 end) sum(case if_pass when 1 then 1 else 0 end)
from VWProduceOrders
laodiao 2002-08-25
  • 打赏
  • 举报
回复
怎么输出还是以前的样子

分子肯定小于分母了,,
icevi 2002-08-25
  • 打赏
  • 举报
回复
因为两个数都是整数,结果就是整数了。所以你对任何一个转成有小数的类型就可以了,比如:
select cast(sum(case if_passed when 1 then 1 else 0 end) as float)/sum(case if_pass when 1 then 1 else 0 end)
from VWProduceOrders


select sum(case if_passed when 1 then 1 else 0 end) /cast(sum(case if_pass when 1 then 1 else 0 end) as float)
from VWProduceOrders
supsuccess 2002-08-25
  • 打赏
  • 举报
回复
select 1.0*sum(case if_passed when 1 then 1 else 0 end)/sum(case if_pass when 1 then 1 else 0 end)
from VWProduceOrders

select cast(sum(case if_passed when 1 then 1 else 0 end)/sum(case if_pass when 1 then 1 else 0 end) as decimal)
from VWProduceOrders

34,575

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧