Here’s how to prepare a simple SQL query using sqlite3 module. The code is following:
Sum of costs query
import sqlite3 connection = sqlite3.connect("my.db") cursor = connection.cursor() c = conn.cursor() c.execute('SELECT SUM(cost) FROM deals WHERE id= "123"') print(c)
The output of above query is the sum of cost from the table “deals” for id = “123”. With such example I’m sure you would be able to adjust the query for your needs.