From 8229b44774fc02f20130acc1405b63f82c62b710 Mon Sep 17 00:00:00 2001 From: Petr Baudis Date: Fri, 6 Jun 2014 20:39:58 +0200 Subject: [PATCH] USAGE.md: Select for listing inventory items by their worth --- brmbar3/USAGE.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/brmbar3/USAGE.md b/brmbar3/USAGE.md index 7076bc9..5821232 100644 --- a/brmbar3/USAGE.md +++ b/brmbar3/USAGE.md @@ -98,3 +98,15 @@ Useful SQL queries select time, transactions.id, description, responsible, amount from transactions left join transaction_splits on transaction_splits.transaction = transactions.id where transaction_splits.account = 1; + +* List all inventory items ordered by their cummulative worth: + + select foo.*, foo.rate * -foo.crbalance as worth from + (select account_balances.*, + (select exchange_rates.rate from exchange_rates, accounts + where exchange_rates.target = accounts.currency + and accounts.id = account_balances.id + order by exchange_rates.valid_since limit 1) as rate + from account_balances where account_balances.acctype = 'inventory') + as foo order by worth; +