Exercise · SQL & Querying
Predict, then run it
Predict the output
daily(windmill, visitors) may be loaded by a job that re-runs. This guarded insert stays idempotent — run it twice and the row lands once:
INSERT INTO daily SELECT 'plum',10 WHERE NOT EXISTS (SELECT 1 FROM daily WHERE windmill='plum'); INSERT INTO daily SELECT 'plum',10 WHERE NOT EXISTS (SELECT 1 FROM daily WHERE windmill='plum'); SELECT windmill, COUNT(*) AS rows FROM daily GROUP BY windmill;
Predict the exact output.