[英]How to replace a PostgreSQL pivot table field (foo_id) in the SELECT of a request by its value taken from the foo table?
Below is my current request made in the foo_bar
pivot table:以下是我在
foo_bar
数据透视表中提出的当前请求:
SELECT
foo_id AS foo,
COUNT(foo_id) AS total
FROM foo_bar
GROUP BY foo_id
How to replace the value of foo_id
in the SELECT
by foo.name
taken from foo
table ?如何更换的价值
foo_id
在SELECT
通过foo.name
取自foo
表?
You need to join the table foo
, assuming both have a foo_id
to join the tables:您需要加入表
foo
,假设两者都有一个foo_id
来加入表:
SELECT
f.name,
COUNT(fb.foo_id) AS total
FROM foo_bar fb
JOIN foo f
ON f.foo_id = fb.foo_id
GROUP BY f.name
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.