-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathanalytical_views.sql
More file actions
61 lines (55 loc) · 1.71 KB
/
analytical_views.sql
File metadata and controls
61 lines (55 loc) · 1.71 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
--------------------------------------------------------------------------------
-- The following statements allow to calculate the aggregates.
-- ALTER statements are given to quickly make changes to existing views.
-- When setting up a new db you can replace alter by create.
--------------------------------------------------------------------------------
-- aggregate average sentiment per provider by cluster (sentiment lookup)
ALTER VIEW
average_sentiment_per_cluster_and_provider_pos_neg
AS
SELECT
AVG(sl.pos_neg_sentiment) 'Sentiment',
rp.root_name 'Provider',
c.cluster_name 'Cluster'
FROM
NewsArticles a
INNER JOIN
ClusterAssignment ca ON a.source_uri = ca.source_uri
AND ca.rank = 1
INNER JOIN
SentimentLookup sl ON a.source_uri = sl.source_uri
INNER JOIN
NewsProviderComplete rp ON a.news_provider = rp.name
INNER JOIN
Cluster c ON ca.cluster_id = c.cluster_id
GROUP BY rp.root_name , c.cluster_name;
-- average sentiment per provider (sentiment lookup)
ALTER VIEW
average_sentiment_per_provider_pos_neg
AS
SELECT
provider.root_name,
avg(pos_neg_sentiment) Sentiment
FROM
NewsArticles articles
INNER JOIN SentimentLookup sl
ON sl.source_uri = articles.source_uri
INNER JOIN NewsProviderComplete provider
ON articles.news_provider = provider.name
GROUP BY provider.root_name;
-- average sentiment per cluster (sentiment lookup)
ALTER VIEW average_sentiment_per_cluster_pos_neg
AS
SELECT
AVG(sl.pos_neg_sentiment) Sentiment,
c.cluster_name Cluster
FROM
NewsArticles a
INNER JOIN
ClusterAssignment ca ON a.source_uri = ca.source_uri
AND ca.rank = 1
INNER JOIN
SentimentLookup sl ON a.source_uri = sl.source_uri
INNER JOIN
Cluster c ON ca.cluster_id = c.cluster_id
GROUP BY c.cluster_name;