我是Oracle SQL的初学者。我正在使用SQL Developer。此查询未执行。我需要像1001,1002这样的每个id,有多少个yes状态和几个no of no状态。预先感谢...。
我使用了此SQL:
SELECT ID, COUNT(STATUS)
FROM TABLE1
WHERE
GROUP BY ID, STATUS
HAVING STATUS = YES OR STATUS = NO;
我有这样的桌子:
id school status
--------------------------
1001 vani YES
1002 sunbeam YES
1001 shristri YES
1002 jain NO
1001 holycross YES
1001 vani NO
我需要类似的输出
id yesstatus Nostatus
-------------------------
1001 3 1
1002 1 1
答案 0 :(得分:8)
您当前的查询语法确实是错误的,但是您可以进行条件聚合:
select id,
sum(case when status = 'YES' then 1 else 0 end) as yesstatus,
sum(case when status = 'NO' then 1 else 0 end) as Nostatus
from table1 t1
where status in ('YES', 'NO')
group by id;
答案 1 :(得分:2)
<v-icon>customIcon</v-icon>
答案 2 :(得分:0)
select status, count(status)
from your_table
group by status