How to make this query better in SQL for this repeated query in 'from clause' -


is there way make query better removing repeated pattern of select in clause? best efficient way write query? using sqlite.

select abs(avg(ravg1) - avg(ravg2)) (select avg(stars) ravg1        movie m join            rating r            on m.mid = r.mid        group r.mid       having year < 1980      ),       (select avg(stars) ravg2        movie m join       rating r on m.mid = r.mid        group r.mid       having year > 1980      ) 

if want difference in ratings years before , after 1980, can use conditional aggregation:

  select abs(avg(case when year < 1980 stars end) -              avg(case when year > 1980 stars end)             )   movie m join        rating r        on m.mid = r.mid; 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -