Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

How could I find average of length each category In SQLite

I don’t know why it’s result like every avg is the same values
I’m trying to solve this remove/add group by I still don’t know why, please help me if I have to add or remove anything else

It’s result like this

name avg(length)
Action 111
Animation 111

same avg values

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I want result like this :

name avg(length)
Action 142
Animation 166

difference avg by their category

This is my statements

SELECT c.name,  AVG(f.length)
FROM film f, category c, film_category fc
WHERE fc.film_id = f.film_id
GROUP BY c.name

>Solution :

You are not joining the category table. This results in a cross join which generates # of categories * # of film_categories records.

SELECT c.name, AVG(f.length)
FROM
   film f
   INNER JOIN film_category fc
       ON f.film_id = fc.film_id
   INNER JOIN category c
       ON fc.category_id = c.category_id
GROUP BY c.name
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading