gpt4 book ai didi

python - 这些查询中的 %% 和 % 是什么意思?

转载 作者:行者123 更新时间:2023-11-28 23:14:40 25 4
gpt4 key购买 nike

我有以下 2 个 Python 代码:

def direct_by_node(self, node, partition_size):
return '''select req.id, req.profile_id as profile
from table1 attr
where id % {0} = {1}'''.format(partition_size, node)

然后

def find_by_node(self, node, partition_size):
return '''select req.id, req.profile_id as profile
from table1 attr
where id %% {0} = {1}'''.format(partition_size, node)

我想知道 2 个 MySQL 查询中的 % 和 %% 是关于什么的?

编辑:

当我在 MySQL Workbench 中尝试 %% 时,看起来我有一个语法错误,看起来 %% 是无效的。

最佳答案

第一个是模运算,计算 id 除以 partition_size 的余数,然后与节点进行比较。

看一个简单的例子:

mysql> SELECT 253 % 7;
-> 1 # because 253 = 36*7 + 1

More function_mod examples

如您所见,%% 不是有效的运算符。

关于python - 这些查询中的 %% 和 % 是什么意思?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44401600/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com