在cursor.execute()中传递多个参数的sql查询

2024-10-01 22:35:55 发布

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

我试图将多个参数传递给sql查询,但它给我带来了错误

以下是查询

cbd_id=[1,10,19,31,37,42,48,57,63,64,65]


cursor.execute('''select t1.id as pid,pxval,pyval from <tbl1> t1 left join (select * from <tbl2> where clubid=? t2 on t1.id=t2.projectid where t1.cityid in (SELECT cityid FROM <tbl3> WHERE cbdid =? group by cityid) and t1.pxval>0 and t2.distance is null order by projectid)''',(cbd_id[i],cbd_id[i]))

它给了我错误

^{pr2}$

但我查了一下没发现问题

任何关于这方面的建议都会有帮助。在

谢谢


Tags: andfromidsqlby错误whereselect
1条回答
网友
1楼 · 发布于 2024-10-01 22:35:55

如错误消息所示,您的SQL命令文本格式不正确。为了清晰起见,您的查询是

select t1.id as pid,pxval,pyval 
from 
    <tbl1> t1 
    left join 
    (
        select * 
        from <tbl2> 
        where clubid=? 
    t2 
        on t1.id=t2.projectid 
where 
    t1.cityid in (
            SELECT cityid 
            FROM <tbl3> 
            WHERE cbdid =? 
            group by cityid) 
    and 
    t1.pxval>0 
    and 
    t2.distance is null 
order by projectid)

请注意,<tbl2>子查询没有右括号。你的疑问应该是

^{pr2}$

相关问题 更多 >

    热门问题