私は私の-SQLクライアントで次のSQLを実行し、正しい結果を返すことができます。私のPythonコードでmysql文を実行するには?
mysql> select cj.name job_name , cb.build_result build_result, count(*) total , GROUP_CONCAT(cb.id) id_list
from ci_build as cb INNER JOIN ci_job as cj
ON cb.job_id = cj.id
where cb.build_time > date_format('2016-04-16','%Y%m%d')
and cb.build_time < date_format('2016-05-27','%Y%m%d')
GROUP BY cj.name , cb.build_result;
をしかし、私は次のPythonコードを使用する場合、それはエラーを返します。
とValueError:サポートされていない形式の文字 'Y'(0x59)インデックス225
でいずれかが私のPythonコードと間違って何を助けることができますか?多くのおかげであなたはほかに%
オペレータのargumewntsといくつかの点で補間したくないパーセント記号を倍増しなければならない〜
start_time = '2016-04-16'
end_time = '2016-05-27'
db = MySQLdb.connect(host='xxxx',port=3306,user='xxxx', passwd='xxxx', db='xxxx',charset='utf8')
sql_query = "select cj.name job_name , cb.build_result build_result, count(*) total , GROUP_CONCAT(cb.id) id_list from ci_build as cb INNER JOIN ci_job as cj ON cb.job_id = cj.id where cb.build_time > date_format(%s,'%Y%m%d') and cb.build_time < date_format(%s,'%Y%m%d') GROUP BY cj.name , cb.build_result; % (start_time , end_time)
cursor = db.cursor()
cursor.execute(sql_query)
all_res=cursor.fetchall()
cursor.close()
db.close()
質問には「閉じる」がありません。最初に修正することはできますか? –