mercredi 9 mars 2016

SQLITE3 in python - any way to save the query which can be used as variable in other queries?

I'm using sqlite3 in my python app and have multiple queries. However, there are certain queries which tend to repeat (e.g 'sum a total quantity of item X in inventory'). Is there any way I can save such query and use it in other queries?

Example of my sum query, say we will name it QuantityInInventory(x)

SELECT SUM(have)
    FROM inventory
    WHERE ID = x
    GROUP BY ID

Example of other, simple, query which would use QuantityInInventory(x)

SELECT ID
    FROM items
    WHERE QuantityInInventory(ID) > 5

Any way to do this? I know these 2 queries can be merged into a nested query (or HAVE query), but that's not the point.

Aucun commentaire:

Enregistrer un commentaire