如何从函数中获取变量以在SQL查询中使用它?
示例:我在Python中有函数:
def week(monday, friday)
monday = '2015-12-14'
friday = '2015-12-18'
...[some other code]...
mysql.execute('''SELECT COUNT(*) FROM orders WHERE (data BETWEEN Date(%s) AND Date(%s)) ''', [monday,friday,])
...[some other code]...
它的工作正确,但此函数monday = '2015-12-14'
这个产生错误:
(只是禁用了变量声明,因为我想从函数中获取它)
def week(monday, friday)
#monday = '2015-12-14'
#friday = '2015-12-18'
...
mysql.execute('''SELECT COUNT(*) FROM orders WHERE (data BETWEEN Date(%s) AND Date(%s)) ''', [monday,friday,])
...[some other code]...
week('2015-12-14', '2015-12-18')
警告:日期时间值不正确:' 1'