0

我有下表,我将如何返回每个出现的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
4

2 回答 2

1

试试这个::

 select id, count(id) as num_occurrences from table where status="pass" group by id
于 2012-06-30T20:37:02.280 回答
-1

查询可能看起来像这样

SELECT COUNT(id) AS num_occurrences FROM tableName WHERE status = 'pass'

但有一件事。id 通常是唯一的,你不应该称它为 columnname id

于 2012-06-30T20:39:54.460 回答