Reputation: 6258
I have two working queries I can't seem to nest.
First one works:
SELECT * FROM accounts WHERE account = 'some_account';
Second works just fine:
SELECT COUNT(*) FROM accounts;
I would like to join these so that I get the count of accounts from the result of the first query and it would look something like this, but I can't do it.
SELECT COUNT(account) FROM (SELECT * FROM accounts WHERE account = 'some_account');
How would I do this?
Upvotes: 1
Views: 39
Reputation: 3233
select count(case when account = 'some_account' then 1 else null end) as Count
FROM accounts
Upvotes: 1
Reputation: 15061
Either
SELECT COUNT(account)
FROM (SELECT account
FROM accounts
WHERE account = 'some_account');
Or
SELECT COUNT(*)
FROM accounts
WHERE account = 'some_account';
Upvotes: 1