Changes between Version 3 and Version 4 of AdvancedReports


Ignore:
Timestamp:
01/24/22 22:53:36 (3 years ago)
Author:
193026
Comment:

--

Legend:

Unmodified
Added
Removed
Modified
  • AdvancedReports

    v3 v4  
    3131order by num_of_reviews_by_reviewer desc
    3232}}}
     33
     34==  Подредување на категориите според средна оценка од сите бизниси кои спаѓаат во нив (во која категорија се најдобро оценетите бизниси), по тромесечие
     35
     36{{{#!sql
     37drop view if exists best_rated_businesses_by_trimesters cascade;
     38create view best_rated_businesses_by_trimesters as
     39
     40
     41SELECT DISTINCT  cc.category_id,
     42                         cc.category_name,
     43
     44
     45
     46CASE WHEN tabela.quarter=1 THEN tabela.category_avg_stars ELSE 0 END AS first_q,
     47CASE WHEN tabela.quarter=2 THEN tabela.category_avg_stars ELSE 0 END AS second_q,
     48CASE WHEN tabela.quarter=3 THEN tabela.category_avg_stars ELSE 0 END AS third_q,
     49CASE WHEN tabela.quarter=4 THEN tabela.category_avg_stars ELSE 0 END AS fourth_q
     50
     51
     52from business bb
     53join category cc on
     54        cc.category_id = bb.category_id
     55join review rr on
     56        rr.business_id = bb.business_id
     57       
     58join (
     59                select distinct c2.category_id, c2.category_name,
     60                extract(quarter FROM r2.review_timestamp) AS quarter,
     61        avg(r2.review_stars) as category_avg_stars
     62  from business b2
     63  join category c2 on
     64                b2.category_id = c2.category_id
     65  join review r2 on
     66                r2.business_id = b2.business_id
     67  group by 1,2,3
     68) as tabela on cc.category_id = tabela.category_id
     69
     70}}}