gpt4 book ai didi

字符串到 SQL IN 参数的 Python 列表

转载 作者:可可西里 更新时间:2023-11-01 08:04:48 25 4
gpt4 key购买 nike

我在 python 中有这个查询:

ssim_group = [S1200,S1300]

query = '''select WIPMessageCnt from waferdata where recipename in (%s) and equipment = ?
and runtype = ? order by stopts desc limit 1''' % (','.join(ssim_grp))

打印查询

当前结果

select WIPMessageCnt from waferdata where recipename in (S1200,S1460) and equipment = ? and runtype = ? order by stopts desc limit 1

预期结果应该是这样的

select WIPMessageCnt from waferdata where recipename in ('S1200','S1460') and equipment = ? and runtype = ? order by stopts desc limit 1

当我尝试将它们放入 SQL 的 IN 参数中时,列表应该对每个元素进行单引号。我怎样才能做到这一点?

最佳答案

ssim_group = ['S1200', 'S1300']
query = '''select WIPMessageCnt from waferdata where recipename in ('%s') and equipment = ? and runtype = ? order by stopts desc limit 1''' % ("','".join(ssim_group))

关于字符串到 SQL IN 参数的 Python 列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34897802/

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