真实的,数学的“取模”表示的是:在Postgres中运作? [英] Real, mathematical "modulo" operation in Postgres?
本文介绍了真实的,数学的“取模”表示的是:在Postgres中运作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Ruby中:
-2 % 24
=> 22
在Postgres中:
In Postgres:
SELECT -2 % 24;
?column?
----------
-2
SELECT mod(-2,24);
mod
-----
-2
I可以轻松地自己写一个,但是我很好奇Postgres是否具有真正的模运算,而不是除法后的余数。
I can easily write one myself, but I'm curious whether Postgres has a real modulus operation, as opposed to remainder after division.
推荐答案
SELECT MOD(24 + MOD(-2, 24), 24);
将返回22而不是-2
will return 22 instead of -2
这篇关于真实的,数学的“取模”表示的是:在Postgres中运作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文