PostgreSQL-我们的客户中哪个电影类别最受欢迎?

时间:2018-11-27 01:17:05

标签: sql postgresql

我正在尝试回答一个特定的问题:“哪个电影类别在我们的客户中最受欢迎?”我可以修改此查询:

SELECT  f.title, COUNT(*) AS RentalCount
  FROM  film f
    INNER JOIN film_category fc ON fc.film_id = f.film_id
    INNER JOIN category c ON c.category_id = fc.category_id
    INNER JOIN inventory i ON i.film_id = f.film_id
    INNER JOIN rental r ON r.inventory_id = i.inventory_id
  WHERE (c.name = 'Sports')
  GROUP BY f.title
  ORDER BY 2 DESC;

This is the ER Diagram

谢谢!

1 个答案:

答案 0 :(得分:0)

您与查询非常接近。基本上,您只需要按类别进行汇总:

dict = {}

choice = input("What is your choice? ")

if choice in dict:
    dict[choice] += 1
else:
    dict[choice] = 1

print(dict)
> {'orange': 1}