Подскажите, как правильно выполнить вот такой запрос
SELECT sum(money_win) FROM messages where sent_to_group = 'Y' and win_lose is not null and DATE_FORMAT(datetime,'%Y-%m-%d') between '2019-05-21' and '2019-05-22'
через mysql.connector.
Я пробую вот так:
day_s = '21.05.2019'
day_p = '22.05.2019'
def current_bank_period(day_s, day_p):
d1 = day_s
d2 = datetime.datetime.strptime(d1, "%d.%m.%Y")
d3 = d2.strftime('%Y-%m-%d')
b1 = day_p
b2 = datetime.datetime.strptime(b1, "%d.%m.%Y")
b3 = b2.strftime('%Y-%m-%d')
try:
dbconfig = read_db_config()
conn = MySQLConnection(**dbconfig)
cursor = conn.cursor()
day_s1 = (d3,)
day_p1 = (b3,)
cursor.execute("SELECT SUM(money_win) FROM messages where sent_to_group = 'Y' and win_lose is not null and DATE_FORMAT(datetime,'%Y-%m-%d') between %s and %s", day_s1, day_p1)
row = cursor.fetchone()
except Error as e:
print(e)
finally:
cursor.close()
conn.close()
if __name__ == '__main__':
current_bank_period(day_s, day_p)
Но у меня возникает ошибка: Not enough parameters for the SQL statement