SQL特定计数查询

时间:2016-10-15 16:25:41

标签: php mysql

"SELECT COUNT (one, two, three, four, five)  FROM $this->tablename where username='$username' and one='Not done' and two='Not done' and three='Not done' and four='Not done' and five='Not done'"

我想计算第一,第二,第三,第四和第五列的“用户名”行的“未完成”值的次数。但是,此查询不起作用。我不知道它是否有效,但我确实感觉这个查询可能会更短。

1 个答案:

答案 0 :(得分:1)

试试这个:

SELECT (one='Not done')
     + (two='Not done')
     + (three='Not done')
     + (four='Not done')
     + (five='Not done')
     AS num_not_done
FROM $this->tablename 
where username='$username'

表达式(column='Not done')将返回10。所以你可以将结果加起来得到匹配数。