In SQLite I need to update row counts of a related table.
The query below does what I want but it walks the table multiple times to get the counts:
U
UPDATE overallCounts SET (total, totalC, totalL, iic, il) =
(SELECT
count(*) as total,
sum(case when source=0 then 1 else 0 end) as totalC,
sum(case when source=2 then 1 else 0 end) as totalL,
case when source=0 then 1 else 0 end as iic,
case when source=2 then 1 else 0 end as il
FROM widgets
WHERE joinId=1234)
WHERE joinId=1234;