How to get column value without decimal in MYSQL

心不动则不痛 提交于 2019-12-11 07:05:54

问题


I have two column in my mysql table A and B and I am fetching records like this:

select (A/B) from table 

But problem is that Above query providing vales something like this:

12.00
3.4
78.9

But I want to get result like this:

12
3
78

Which MySQL function I will use for this ??

Thanks


回答1:


If you want 78.9 to be 78 then

SELECT Floor(A/B) FROM table

If you want 78.9 to be 79 then

SELECT Ceiling(A/B) FROM table




回答2:


Just ROUND your result:

SELECT ROUND(A/B, 0) FROM table

You can also combine ROUND with FLOOR if you always want to round down.




回答3:


http://dev.mysql.com/doc/refman/5.0/en/precision-math-rounding.html



来源:https://stackoverflow.com/questions/5660199/how-to-get-column-value-without-decimal-in-mysql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!