Repository navigation
Expand file tree
/
Copy pathWave_queries.sql
More file actions
73 lines (57 loc) · 2.47 KB
/
Copy pathWave_queries.sql
File metadata and controls
73 lines (57 loc) · 2.47 KB
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
--- QUESTION 1 ---
SELECT count(*) FROM public.users;
--- QUESTION 2 ---
SELECT COUNT(*) FROM public.transfers
WHERE send_amount_currency = 'CFA';
--- QUESTION 3 ---
SELECT COUNT(DISTINCT u_id) FROM public.transfers
WHERE send_amount_currency = 'CFA';
--- QUESTION 4 ---
SELECT COUNT(*), EXTRACT (month FROM when_created) AS month FROM public.agent_transactions
WHERE EXTRACT (year FROM when_created) = '2018'
GROUP BY
EXTRACT (MONTH FROM when_created);
--- QUESTION 5 ---
--------------- Net Depositors ---------
SELECT COUNT(agents.agent_id) AS number_net_depositors
FROM public.agent_transactions, public.agents
WHERE amount < 0
AND agent_transactions.agent_id = agents.agent_id
AND agent_transactions.when_created > current_date - interval '7 days';
-------------- Net Withdrawers -----------
SELECT COUNT(agents.agent_id) AS number_net_withdrawers
FROM public.agent_transactions, public.agents
WHERE amount > 0
AND agent_transactions.agent_id = agents.agent_id
AND agent_transactions.when_created > current_date - interval '7 days';
--- QUESTION 6 ---
SELECT COUNT(atx_id) AS volume, city
FROM public.agent_transactions
INNER JOIN public.agents ON agents.agent_id = agent_transactions.agent_id
WHERE agent_transactions.when_created > now() -INTERVAL '7 days'
GROUP BY city;
--- QUESTION 7 ---
SELECT COUNT(atx_id) AS volume, city, country
FROM public.agent_transactions
INNER JOIN public.agents ON agents.agent_id = agent_transactions.agent_id
WHERE agent_transactions.when_created > now() -INTERVAL '7 days'
GROUP BY city, country;
--- QUESTION 8 ---
SELECT COUNT(atx_id) AS volume, kind, country
FROM public.agent_transactions, public.transfers, public.agents
WHERE agent_transactions.when_created BETWEEN '2018-11-23' AND '2018-12-30'
GROUP BY kind, country;
--- QUESTION 9 ---
SELECT DISTINCT COUNT(transfers.source_wallet_id) AS Unique_Senders,
COUNT(transfer_id) AS transaction_count,
transfers.kind AS transfer_Kind,
wallets.ledger_location AS Country,
SUM(transfers.send_amount_scalar) AS Volume
FROM transfers INNER JOIN wallets ON transfers.source_wallet_id = wallets.wallet_id
WHERE (transfers.when_created > (NOW() - INTERVAL '7 days'))
GROUP BY wallets.ledger_location, transfers.kind;
--- QUESTION 10 ---
SELECT source_wallet_id, send_amount_scalar FROM transfers
WHERE send_amount_currency = 'CFA'
AND (send_amount_scalar>10000000)
AND (transfers.when_created > (NOW() - INTERVAL '1 month'));