5 | | {{{#!sql |
6 | | select |
7 | | c.category_id, |
8 | | c.category_name, |
9 | | avg(r.review_stars) as category_avg_stars |
10 | | from review r |
11 | | inner join business b on |
12 | | r.business_id = b.business_id |
13 | | inner join category c on |
14 | | b.category_id = c.category_id |
15 | | group by c.category_id |
16 | | order by category_avg_stars desc |
17 | | }}} |
18 | | |
19 | | |
20 | | == Приказ на бројот на reviews според reviewer, подредени по опаѓачки редослед |
21 | | |
22 | | {{{#!sql |
23 | | select |
24 | | rr.reviewer_name, |
25 | | count(r.review_id) as num_of_reviews_by_reviewer |
26 | | from |
27 | | review r |
28 | | inner join reviewer rr on |
29 | | r.reviewer_id = rr.reviewer_id |
30 | | group by rr.reviewer_name |
31 | | order by num_of_reviews_by_reviewer desc |
32 | | }}} |
| 42 | |
| 43 | |
| 44 | == Приказ на бројот на reviews според reviewer по тромесечие |
| 45 | |
| 46 | |
| 47 | {{{#!sql |
| 48 | drop view if exists num_of_reviews_by_reviewer_by_trimester cascade; |
| 49 | create view num_of_reviews_by_reviewer_by_trimester as |
| 50 | |
| 51 | |
| 52 | SELECT DISTINCT |
| 53 | rrr2.reviewer_id, |
| 54 | rrr2.reviewer_name, |
| 55 | |
| 56 | |
| 57 | |
| 58 | CASE WHEN tabela.quarter=1 THEN tabela.num_of_reviews_by_reviewer ELSE 0 END AS first_q, |
| 59 | CASE WHEN tabela.quarter=2 THEN tabela.num_of_reviews_by_reviewer ELSE 0 END AS second_q, |
| 60 | CASE WHEN tabela.quarter=3 THEN tabela.num_of_reviews_by_reviewer ELSE 0 END AS third_q, |
| 61 | CASE WHEN tabela.quarter=4 THEN tabela.num_of_reviews_by_reviewer ELSE 0 END AS fourth_q |
| 62 | |
| 63 | |
| 64 | from |
| 65 | review rrr |
| 66 | inner join reviewer rrr2 on |
| 67 | rrr.reviewer_id = rrr2.reviewer_id |
| 68 | |
| 69 | join ( |
| 70 | select |
| 71 | distinct r2.reviewer_name, |
| 72 | r2.reviewer_id, |
| 73 | extract(quarter FROM r.review_timestamp) AS quarter, |
| 74 | count(r.review_id) as num_of_reviews_by_reviewer |
| 75 | from |
| 76 | review r |
| 77 | inner join reviewer r2 on |
| 78 | r.reviewer_id = r2.reviewer_id |
| 79 | group by 1,2,3 |
| 80 | ) as tabela on rrr2.reviewer_id = tabela.reviewer_id |
| 81 | |
| 82 | |
| 83 | |
| 84 | }}} |