Skip to content
Advertisement

Retrive data of last month using Python with source as MYSQL

I am getting an error while retrieving data of the last month using python. What is the best approach for the given piece of code?

I am not able to get solution, What changes can I do. I am using MYSQL as my source database and Python 3.7.4 as my programming language.

Since error is big, posting it in two parts :

Part1

enter image description here

Part2

enter image description here

Advertisement

Answer

You are missing a WHERE clause:

But I prefer to use ? placeholders for the parameters and pass them as a tuple:

Note that if the column UsageDateTime‘s data type is DATETIME or TIMESTAMP then instead of WHERE UsageDateTime BETWEEN ... you should use WHERE DATE(UsageDateTime) BETWEEN ..., otherwise you will miss the rows of the last day of the month.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement