0
我想使用下面的查詢,我做了一些date_format操作,我也想用一些佔位符。不幸的是,查詢失敗,因爲它不會取代佔位符。該查詢如下:Python MySQL - 帶參數和其他佔位符的mysqldb查詢
query_with_parameters = """select ID, IP_src, IP_dst, sum(bytes) as Total_Bytes, count(*) as total_packets,\
(sum(bytes)/count(*)) as Average, date_format(date, "%H") as Hour , date_format(date, "%d %m %Y")\
as date from Packets where date BETWEEN %s and %s group by IP_src,\
IP_dst, Hour, date order by IP_src, IP_dst, Hour, date;"""
,我試圖通過使用它:
cursor.execute(query_with_parameters, ('2013-06-30 00:00:00' , '2013-06-30 23:59:59'))
我使用MySQLdb的作爲庫和Python 2.7 我得到的例外是:
(<type 'exceptions.ValueError'>, ValueError("unsupported format character 'H' (0x48) at index 144",), <traceback object at 0x33447a0>)
任何想法? 謝謝