python 语言,如何拼接sql

例如a=123
如果a=0,sql 为 select * from table
如果a!=0,sql为select * from table where a=123
如何用python实现

a = 123
sql = 'select * from table' if not a else 'select * from table  where a={}'.format(a)

追问

那如果这个table涉及多表查询,且不止一个参数要去判断呢

温馨提示:答案为网友推荐,仅供参考
相似回答