-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalysis.sql
More file actions
84 lines (67 loc) · 1.68 KB
/
Copy pathanalysis.sql
File metadata and controls
84 lines (67 loc) · 1.68 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
74
75
76
77
78
79
80
81
82
83
84
-- Payment Analytics Portfolio Project
-- Synthetic dataset: transactions.csv
-- 1. Total transaction volume
SELECT
SUM(amount) AS total_payment_volume
FROM transactions
WHERE status = 'Success';
-- 2. Total commission revenue
SELECT
SUM(commission) AS total_commission_revenue
FROM transactions
WHERE status = 'Success';
-- 3. Transaction count by status
SELECT
status,
COUNT(*) AS transaction_count
FROM transactions
GROUP BY status
ORDER BY transaction_count DESC;
-- 4. Active users
SELECT
COUNT(DISTINCT user_id) AS active_users
FROM transactions
WHERE status = 'Success';
-- 5. Average transaction amount
SELECT
ROUND(AVG(amount), 2) AS average_transaction_amount
FROM transactions
WHERE status = 'Success';
-- 6. Analytics by category
SELECT
category,
COUNT(*) AS transaction_count,
SUM(amount) AS total_amount,
SUM(commission) AS total_commission,
ROUND(AVG(amount), 2) AS average_amount
FROM transactions
WHERE status = 'Success'
GROUP BY category
ORDER BY total_amount DESC;
-- 7. Daily transaction dynamics
SELECT
transaction_date,
COUNT(*) AS transaction_count,
SUM(amount) AS daily_volume,
SUM(commission) AS daily_commission
FROM transactions
WHERE status = 'Success'
GROUP BY transaction_date
ORDER BY transaction_date;
-- 8. Top users by payment volume
SELECT
user_id,
COUNT(*) AS transaction_count,
SUM(amount) AS total_amount
FROM transactions
WHERE status = 'Success'
GROUP BY user_id
ORDER BY total_amount DESC;
-- 9. Transaction success rate
SELECT
ROUND(
100.0 * SUM(CASE WHEN status = 'Success' THEN 1 ELSE 0 END)
/ COUNT(*),
2
) AS success_rate_percent
FROM transactions;