0

我需要获取特定 id 的列计数,但仅当列值为“是”时。我猜以下是错误的。中(主键)

SELECT COUNT(mt.currentstate = 'Yes') AS currentstate FROM mytable mt WHERE mid = 100 GROUP BY mid;

对于 COUNT 值,我只需要来自 mt.currentstate = 'Yes' 列,但对于 ResultSet,我需要获取 mt.currentstate = 'Yes' 或 'No' 的所有值

4

3 回答 3

3

你可以试试下面的查询,如果我不穿的话它会起作用。

SELECT COUNT(mt.mid) AS counter FROM mytable mt WHERE mid = 100 AND mt.currentstate = "YES" GROUP BY mid;

谢谢!

于 2013-10-16T05:48:54.353 回答
1

尝试这个:

SELECT COUNT(*) AS currentstate FROM mytable WHERE mid = 100 AND currentstate='Yes';

编辑:“现在,如果我将 mt.currentstate = 'Yes' 放在 WHERE 子句中,它将过滤 mt.currentstate = 'Yes' 的所有行,但我需要 mt.currentstate = 'No' 行中的其他列值。 .我要做什么?

SELECT currentstate, COUNT(*) AS c FROM mytable WHERE mid = 100 GROUP BY currentstate;
于 2013-10-16T05:49:13.577 回答
0
SELECT COUNT(mt.mid) AS currentstate FROM mytable mt
WHERE mid = 100 and mt.currentstate = 'Yes' GROUP BY mid;
于 2013-10-16T05:48:59.200 回答