如何使用LIMIT在python3中编写mysql准备的SELECT语句?

2024-07-04 06:17:33 发布

您现在位置:Python中文网/ 问答频道 /正文

idValue = 100
limitValue = 10000
query = "SELECT count(*) as count FROM oneTable WHERE id = (%s) LIMIT (%s)";
cursor.execute(query, (idValue, limitValue ))

这好像不管用。它只获取与id对应的一条记录


Tags: fromidexecuteascount记录wherequery
2条回答

我想这应该是你想要的。若您打印结果,您可以看到您的查询结果。你知道吗

idValue = 100
limitValue = 10000
query = "SELECT count(*) as count FROM oneTable WHERE id = {0} limit {1}".format(idValue,limitValue)
cursor.execute(query)
result = cursor.fetchall()

问题中的原始查询不起作用。在我的代码中有一些其他的bug,因此它停止了工作。谢谢@Baran

相关问题 更多 >

    热门问题