File size: 404 Bytes
27ec678
 
 
1
2
3
4
-- Cost of goods sold, by entity
-- Debits less credits on 5000 by month, per entity.
SELECT strftime(e.entry_date, '%Y-%m') AS month, e.entity AS grp, -sum(l.credit - l.debit) AS value FROM ledger.journal_line l JOIN ledger.journal_entry e USING (entry_id) WHERE l.account_code IN ('5000') AND e.entry_date >= TIMESTAMP '2023-10-01' AND e.entry_date < TIMESTAMP '2026-10-01' GROUP BY 1, 2 ORDER BY 1, 2