First time post here.
I've got what I thought was a relatively simple query... but not so much.
How do I fix this?
I have organization, account and investment tables. Multiple inv's per acct, multiple accts per org. Org's have names, accts (aka funds) have status and type, and investments have cost.
I have a nice summary report showing, for each organization and each account status and type, a summary of:
Org, Acct Status, Acct Type, # investments and total value
WHAT I NEED: instead of # investments, I need # accounts in each group (org/status/type).
MY PROBLEM: everything I've tried, I end up with # investments because the underlying grouping is on org/status/type
How do I condense the multiple investment records-per-acct so that I can get an account-count?
My closest thought, which didn't work, was to get
Count(First(account.acct_id))
...but you can't do that.
ANY IDEAS mucho appreciated!
Pete
I've got what I thought was a relatively simple query... but not so much.
How do I fix this?
I have organization, account and investment tables. Multiple inv's per acct, multiple accts per org. Org's have names, accts (aka funds) have status and type, and investments have cost.
I have a nice summary report showing, for each organization and each account status and type, a summary of:
Org, Acct Status, Acct Type, # investments and total value
WHAT I NEED: instead of # investments, I need # accounts in each group (org/status/type).
MY PROBLEM: everything I've tried, I end up with # investments because the underlying grouping is on org/status/type
How do I condense the multiple investment records-per-acct so that I can get an account-count?
My closest thought, which didn't work, was to get
Count(First(account.acct_id))
...but you can't do that.
ANY IDEAS mucho appreciated!
Pete
Code:
SELECT org.nm AS Org, account.acct_stat AS fundStatus, account.acct_type AS fundType, Count(account.acct_id) AS hldgsCount, Sum(acct_inv_balance.cost) AS Total
FROM acct_inv_balance, org INNER JOIN account ON org.org_id = account.org_id
WHERE account.acct_id=[acct_inv_balance].[acct_id]
GROUP BY org.nm, account.acct_stat, account.acct_type
ORDER BY org.nm, account.acct_stat, account.acct_type;