-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreate_views.sql
41 lines (34 loc) · 1.19 KB
/
create_views.sql
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
CREATE VIEW top_three AS
SELECT path, count(*) AS num
FROM log
WHERE path LIKE '%article%'
GROUP BY path
ORDER BY num DESC
LIMIT 3;
CREATE VIEW author_titles AS
SELECT authors.name, articles.title, articles.slug
FROM articles
JOIN authors
ON authors.id = articles.author
ORDER BY name;
CREATE VIEW article_count AS
SELECT path, count(*) AS num
FROM log
WHERE path LIKE '%article%'
GROUP BY path;
CREATE VIEW requests_made AS
SELECT date_trunc('day', time), count(*) AS num_requests
FROM log
GROUP BY date_trunc('day', time);
CREATE VIEW request_errors AS
SELECT date_trunc('day', time), status, count(*) AS num_errors
FROM log
WHERE status != '200 OK'
GROUP BY date_trunc('day', time), status
ORDER BY date_trunc('day', time);
CREATE VIEW error_comparisons AS
SELECT to_char(requests_made.date_trunc, 'FMMonth DD, YYYY'),
round(cast(num_errors AS numeric)/num_requests*100,2) AS percentage
FROM request_errors
JOIN requests_made
ON request_errors.date_trunc = requests_made.date_trunc;