aboutsummaryrefslogtreecommitdiff
path: root/res/sql/views/orcl_accounts.sql
diff options
context:
space:
mode:
authorPacien TRAN-GIRARD2015-01-27 18:01:45 +0100
committerPacien TRAN-GIRARD2015-01-27 18:27:51 +0100
commitafe377a9b10b5c1b2badc74d4b9b636e7c4d0cbf (patch)
treee6808c16b8bf7b7a2cd79435706465181cbe4295 /res/sql/views/orcl_accounts.sql
parent999d0ebce6b2f4ba39ee55daa52ca33f5fac657c (diff)
downloadminibay-afe377a9b10b5c1b2badc74d4b9b636e7c4d0cbf.tar.gz
Add E-R model and SQL bootstrap scripts
Diffstat (limited to 'res/sql/views/orcl_accounts.sql')
-rw-r--r--res/sql/views/orcl_accounts.sql31
1 files changed, 31 insertions, 0 deletions
diff --git a/res/sql/views/orcl_accounts.sql b/res/sql/views/orcl_accounts.sql
new file mode 100644
index 0000000..400d38f
--- /dev/null
+++ b/res/sql/views/orcl_accounts.sql
@@ -0,0 +1,31 @@
1CREATE OR REPLACE VIEW accounts AS
2
3 SELECT
4 users.uuid AS user_uuid,
5 COALESCE(transactions.balance, 0) AS balance,
6 COALESCE(sales.open_bids, 0) AS open_bids,
7 COALESCE(transactions.balance, 0) - COALESCE(sales.open_bids, 0) AS equity
8
9 FROM users
10
11 LEFT OUTER JOIN (
12 SELECT
13 user_uuid,
14 SUM(transactions.amount) AS balance
15
16 FROM transactions
17 WHERE transaction_date < current_datetime()
18 GROUP BY user_uuid
19 ) transactions
20 ON transactions.user_uuid = users.uuid
21
22 LEFT OUTER JOIN (
23 SELECT
24 best_bidder_uuid,
25 SUM(sales.best_offer + sales.charges) AS open_bids
26
27 FROM sales
28 WHERE end_date > current_datetime()
29 GROUP BY best_bidder_uuid
30 ) sales
31 ON sales.best_bidder_uuid = users.uuid;