forked from natebrennand/Trading-Wheel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
queries.txt
55 lines (48 loc) · 1010 Bytes
/
queries.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
Nate Brennand: nsb2142
Matt Garbis: meg228
All data except the portofolio_statistics is real world data.
Code can be found here:
https://github.com/nsb2142/Trading-Wheel
/* Highest Value any portfolio reaches */
SELECT
CS.user_id,
S.strategy_name,
MAX(T.portfolio_value)
FROM
trade T,
action A,
create_strategy CS,
strategy S
WHERE
CS.strategy_id = A.strategy_id
AND S.strategy_id = CS.strategy_id
AND T.trade_id = A.trade_id
GROUP BY
CS.user_id,
S.strategy_name;
/* Number of trades made by each strategy for each person */
Select DISTINCT
S.strategy_name,
CS.user_id,
COUNT(T.trade_id)
FROM create_strategy CS,
action A,
trade T,
strategy S
WHERE
CS.strategy_id = A.strategy_id
AND S.strategy_id = CS.strategy_id
AND A.trade_id = T.trade_id
GROUP BY
S.strategy_name,
CS.user_id;
/* Volume of each stock in 2009, in order */
Select Distinct
Q.security,
SUM(Q.volume)
FROM
query_data Q
WHERE
extract(year from Q.time) = 2009
GROUP BY
Q.security;