How to sorting data by input?

Question:

I have problem with sqlite3 in Python. I want sorting data from database by inputing date.

Here is my code, is it good way?

 if choice == 1:
        # Suma 'Wartość' z simple.db 
       
        dt = input()
        dt2 = input()
        cursor.execute('''
            SELECT 
                SUM(Wartość),
                Data 
            FROM 
                kalendarz
            WHERE
                Data between () and () VALUES (?, ?);''', (dt, dt2))
Asked By: SiemowitJarilo

||

Answers:

you are summing the column Wartość without group by try this instead:

 if choice == 1:       
    dt = input()
    dt2 = input()
    cursor.execute(f'''
        SELECT 
            Wartość,
            Data 
        FROM 
            kalendarz
        WHERE
            Data between '{dt}' and '{dt2}'
        ORDER BY
            Data''')
Answered By: Ghassen Sultana
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.