-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathreal_time_steaming_flink_kafka2.sql
More file actions
66 lines (56 loc) · 1.44 KB
/
real_time_steaming_flink_kafka2.sql
File metadata and controls
66 lines (56 loc) · 1.44 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
CREATE TABLE processed_events_aggregated (
event_hour TIMESTAMP(3),
host VARCHAR,
num_hits BIGINT
);
CREATE TABLE processed_events_aggregated_source (
event_hour TIMESTAMP(3),
host VARCHAR,
referrer VARCHAR,
num_hits BIGINT
);
WITH conteo AS (
SELECT COUNT(event_hour) AS count_event, host
FROM processed_events_aggregated
WHERE host LIKE '%techcreator%'
GROUP BY host
),
total AS (
SELECT SUM(count_event) AS total_events
FROM conteo
)
SELECT
c.host,
c.count_event,
c.count_event / t.total_events AS pct_event
FROM conteo c
CROSS JOIN total t
WHERE host IN ('zachwilson.techcreator.io', 'zachwilson.tech', 'lulu.techcreator.io');
SELECT
host,
AVG(event_count) AS avg_events_per_session
FROM (
SELECT
host,
COUNT(*) AS event_count
FROM processed_events_aggregated
WHERE host LIKE '%techcreator%'
--WHERE host IN ('zachwilson.techcreator.io', 'zachwilson.tech', 'lulu.techcreator.io')
GROUP BY host
) session_events
GROUP BY host;
WITH session_events AS(
SELECT
host,
COUNT(*) AS event_count
FROM processed_events_aggregated
--WHERE host IN ('zachwilson.techcreator.io', 'zachwilson.tech', 'lulu.techcreator.io')
GROUP BY host
)
SELECT
host,
AVG(event_count) AS avg_events_per_session
FROM session_events
GROUP BY host;
SELECT * FROM processed_events_aggregated;
SELECT * FROM processed_events_aggregated_source;