我有下表,如何返回id
status=pass
的出现次数
id status
111 pass
111 fail
333 pass
222 pass
333 pass
222 fail
以便结果集看起来像这样
id num_occurrences
111 1
222 1
333 2
答案 0 :(得分:1)
试试这个::
select id, count(id) as num_occurrences from table where status="pass" group by id
答案 1 :(得分:-1)
查询可能看起来像那样
SELECT COUNT(id) AS num_occurrences FROM tableName WHERE status = 'pass'
但有一件事。 id通常是唯一的,你不应该称之为列名id