sql查询中的数学计算给出了错误的结果 [英] math calculation in sql query gives wrong result

查看:43
本文介绍了sql查询中的数学计算给出了错误的结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

先生,我有一个简单的查询: -



选择sname,35 +(50-35)*(20/50)作为tt来自学生



这个等式的答案是6,但它给出了35.我的错误是什么。

sir, i have a simple query :-

select sname,35+(50-35)*(20/50) as tt from student

the answer of this equation is 6 but it give 35. what is my mistake.

推荐答案

所有,该等式的结果应为41( 35+(50-35)*(20/50 )在谷歌



要获得这个结果,你应该做一些像



First of all,the result of that equation should be 41 (35+(50-35)*(20/50) in Google )

To get the this result,you should do something like

select 35+(50-35) * (CONVERT(DECIMAL(4,2), 20) / CONVERT(DECIMAL(4,2), 50)) as tt





希望有帮助



Hope it helps


试试这个

try this
select sname,35+((50.0-35.0)*(20.0/50.0)) as tt from student



默认为int int然后转换为float。


as default it int so convert then into float.


这篇关于sql查询中的数学计算给出了错误的结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆