I need a way to insert a value if the value doesn't exist and if it does it should increase that value by another variable.
This is what my table looks like:
CREATE TABLE IF NOT EXISTS table(
Id INTEGER PRIMARY KEY,
Date TEXT,
Quantity INTEGER
Whenever i add a date to the database, with a quantity i want it to, add the quantity to the "quantity" in table. So every "Date" would only have 1 "Quantity" assigned.
Just a small example:
INSERT INTO Table (Date, Quantity) VALUES('%s', Quantity+%s)) % ('12/5/2013', 20);
If there already is a record that looks like ('12/5/2013', 5) it would be ('12/5/2013', 25) instead.
I found 1 very similar question, but i don't understand, how i also make the integer increase.. Another Question
replace or insertsounds pretty self-explenary. Thecoalesceis new to me but according to the docs it returns the first non-null argument passed into, So if the select returns null (as there is no record for given date yet) the second paramter is used as a fallback. In your case you just don't wantcoalesce(SELECT val+1 …, 1)but something likecoalesce(SELECT quantity+quantity …, quantitty)sqlite.org/lang_corefunc.html