-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOperational analytics.sql
More file actions
60 lines (44 loc) · 1.53 KB
/
Operational analytics.sql
File metadata and controls
60 lines (44 loc) · 1.53 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
create database op_db;
use op_db;
select *
from jobdata;
/*1.Number of jobs reviewed: Amount of jobs reviewed over time.
Your task: Calculate the number of jobs reviewed per hour per day for November 2020?*/
select ds,
round((count(distinct job_id)/sum(time_spent))*3600,2) as jobs_reviewed_per_hour_per_day
from jobdata
group by ds
order by ds;
/*2.Throughput: It is the no. of events happening per second.
Your task: Let’s say the above metric is called throughput. Calculate 7 day rolling average of throughput? For throughput,
do you prefer daily metric or 7-day rolling and why?*/
with event_table as
(select ds,
round((count(distinct event)/sum(time_spent)),2) as event_per_second_daily
from jobdata
group by ds
order by ds
)
select ds, event_per_second_daily,
avg(event_per_second_daily) over(order by ds rows between 6 preceding and current row) as 7_days_rolling_avg
from event_table
group by ds
order by ds ;
/*3.Percentage share of each language: Share of each language for different contents.
Your task: Calculate the percentage share of each language in the last 30 days?*/
select language,
count(*)*100/total as percentage
from jobdata cross join
(select count(*) as total
from jobdata) as totaldata
group by language
order by count(*) desc;
/*4.Duplicate rows: Rows that have the same value present in them.
Your task: Let’s say you see some duplicate rows in the data. How will you display duplicates from the table?*/
select * from
(
select *,
row_number()over(partition by job_id) as rownum
from jobdata
)a
where rownum>1;