Python SQL查询与函数中的变量

时间:2015-12-12 11:38:04

标签: python mysql sql

如何从函数中获取变量以在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'

0 个答案:

没有答案