像excel一样在SQL中修改负数 [英] Mod negative numbers in SQL just like excel

查看:35
本文介绍了像excel一样在SQL中修改负数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在 SQL 服务器中复制 mod 函数时遇到问题.

I'm having trouble replicating the mod function in SQL sever.

在 Excel 中,mod (-3, 7) = 4.但在 SQL 中,-3 % 7 = -3

In excel, mod (-3, 7) = 4. But in SQL, -3 % 7 = -3

我使用了 % 错误,还是 SQL 的模式不同?

Am I using % wrong, or does SQL do mod differently?

推荐答案

对于 x 的正值和负值,这将给出介于 0 和 n - 1 之间的结果:

This will give a result between 0 and n - 1 for both positive and negative values of x:

((x % n) + n) % n

这篇关于像excel一样在SQL中修改负数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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