From e567d36e7761d7b3044aae2206434ef7e68c13b9 Mon Sep 17 00:00:00 2001 From: brmbar Date: Tue, 6 Aug 2013 22:18:23 +0200 Subject: [PATCH] USAGE: Add some useful SQL queries --- brmbar3/USAGE.md | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/brmbar3/USAGE.md b/brmbar3/USAGE.md index b2526c7..11eeec2 100644 --- a/brmbar3/USAGE.md +++ b/brmbar3/USAGE.md @@ -74,3 +74,22 @@ implementation yet; it's not entirely clear yet what is the proper way to do this from the accounting standpoint. In the meantime, you can use SQL INSERTs to manually create a transaction with appropriate transaction splits (see doc/architecture for details on splits). + + +Useful SQL queries +------------------ + +* Compute sum of sold stock: + + select sum(amount) from transactions + left join transaction_splits on transaction_splits.transaction = transactions.id + where description like '% sale %' and side = 'debit';` + +* List of items not covered by inventory check: + + select * from account_balances + where id not in (select account from transactions + left join transaction_splits on transaction_splits.transaction = transactions.id + where description like '% inventory %') + and acctype = 'inventory' +