USAGE: Add some useful SQL queries

This commit is contained in:
brmbar 2013-08-06 22:18:23 +02:00
parent d74ca2b6c0
commit e567d36e77

View file

@ -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 way to do this from the accounting standpoint. In the meantime, you
can use SQL INSERTs to manually create a transaction with appropriate can use SQL INSERTs to manually create a transaction with appropriate
transaction splits (see doc/architecture for details on splits). 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'