如何在mysql中划分和舍入?

时间:2022-07-28 22:29:53

I have a table with data like this:

我有一个包含这样数据的表:

ID  customer_id rewards_points (target)
1   23796        10               4
2   24196        20               7
3   24197        30              10
4   24198        40              14
5   24199        50              17

I want to divide all values under rewards_points column by 3, then round up to the nearest integer. What query can I run to accomplish this?

我想将rewards_points列下的所有值除以3,然后向上舍入到最接近的整数。我可以运行什么查询来完成此任务?

Thank you!

2 个解决方案

#1


To get the value

获得价值

SELECT CEILING(theField/3.0) FROM theTable WHERE ...

The set the value

设定值

UPDATE theTable SET theField = CEILING(theField/3.0) WHERE ....;

#2


try this:

select rewards_points DIV 3 as result from table;

#1


To get the value

获得价值

SELECT CEILING(theField/3.0) FROM theTable WHERE ...

The set the value

设定值

UPDATE theTable SET theField = CEILING(theField/3.0) WHERE ....;

#2


try this:

select rewards_points DIV 3 as result from table;