我有两个工作查询,我似乎无法嵌套。
第一个有效:
SELECT * FROM accounts WHERE account = 'some_account';
其次很好用:
SELECT COUNT(*) FROM accounts;
我想加入这些,以便从第一个查询的结果得到帐户的数量,它看起来像这样,但我不能这样做。
SELECT COUNT(account) FROM (SELECT * FROM accounts WHERE account = 'some_account');
我该怎么做?
答案 0 :(得分:1)
无论
SELECT COUNT(account)
FROM (SELECT account
FROM accounts
WHERE account = 'some_account');
或者
SELECT COUNT(*)
FROM accounts
WHERE account = 'some_account';
答案 1 :(得分:1)
select count(case when account = 'some_account' then 1 else null end) as Count
FROM accounts