舍入sql整数到最近的小时 [英] round sql integer to nearest hour
问题描述
我有一个格式为整数的列(值为2300,0040,2090),其值代表军事时间。将这些值舍入到最接近的小时最简单的方法是什么?所以,如果是2330,则可以舍入到2400等。我不希望将值转换为日期/时间。
I have a column formatted as an integer (values ex. 2300, 0040, 2090) with values representing military time. What would be the easiest way to round these values to the nearest hour? So, if 2330, would round up to 2400, etc. I don't want the values converted to date/time.
我正在寻找SQL中的帮助或Excel。谢谢。
I'm looking for help in either SQL or Excel. Thanks.
推荐答案
简单算术。大多数SQL方言支持<$ c $ c> floor():
Simple arithmetic. Most SQL dialects support floor()
:
select floor((col+70) / 100) * 100
在Excel中,您将使用:
In Excel, you would use:
select floor((col+70) / 100, 1) * 100
0000和2400仍有问题。如果这是一个问题,那么你需要使用条件逻辑或模运算。
You still have an issue with 0000 and 2400. If that is an issue, then you would need to use conditional logic or modulo arithmetic.
这篇关于舍入sql整数到最近的小时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!