I'm new to Postgres. I have a query that involves 4 tables. My tables look like the following:
User Account Transaction Action
---- ------- ----------- ------
ID ID ID ID
Name UserID AccountID AccountID
Description Description
For each user, I'm trying to figure out: How many accounts they have, and how many total transactions and actions have been taken across all accounts. In other words, I'm trying to generate a query whose results will look like the following:
User Accounts Transactions Actions
---- -------- ------------ -------
Bill 2 27 7
Jack 1 7 0
Joe 0 0 0
How do I write a query like this? Currently, I'm trying the following:
SELECT
u.Name,
(SELECT COUNT(ID) FROM Account a WHERE a.UserID = u.ID) as Accounts
FROM
User u
Now, I'm stuck though.