在SQL查询中使用LIKE时获取语法错误

时间:2018-07-14 02:17:55

标签: mysql sql mysql-connector-python

当我这样创建sql查询时:

param = (date, )
query = SELECT date_added from deploy_requests WHERE date_added LIKE '%s %'
query.execute(query, param)

我遇到语法错误

但是如果我使用不推荐的方式

query = SELECT date_added from deploy_requests WHERE date_added LIKE '{} %'.format(date)

1 个答案:

答案 0 :(得分:0)

我发现,这就是我的方法。

def get_deployment_times(date):
    date = "{}%".format(date)
    param = (date, )
    query = "SELECT date_added from deploy_requests WHERE date_added LIKE %s"