【发布时间】:2021-10-08 21:59:34
【问题描述】:
我有多个查询,我想将它们组合成一个 9 表连接(可能是个坏主意?)以从表中获取 4 个特定列。但我不确定最好的方法是什么。
我想得到total number of genres watched by each country name.
所以我想要的列是:
name 来自类别表
country 来自国家/地区表
还有一个新创建的列num_rentals integer
https://www.postgresqltutorial.com/postgresql-sample-database/
我不确定我会如何处理这个问题。我是否应该将所有其他表加入 rental 表并执行 groupby/count 以获得该国家/地区的租赁数量?
查看表格后,我发现它们都通过一个属性相互关联...例如城市中的 country_id、地址中的 city_id、客户中的 address_id、出租中的 customer_id
SELECT rental.customer_id FROM rental AS rental;
SELECT country.country FROM country AS country;
SELECT city.country_id FROM city AS city;
SELECT address.city_id FROM address AS address;
SELECT customer.address_id FROM customer AS customer;
最好的方法是什么?
【问题讨论】:
-
我可以知道您使用哪个工具来创建该图表吗?
-
嗨,我没有从这个网站 postgresqltutorial.com/postgresql-sample-database 创建图表。我确实知道 lucidchart.com 有一个类似的工具来创建这样的图表
标签: sql postgresql