"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'"
我想计算在“用户名”行的第一、二、三、四和五列中找到“未完成”值的次数。然而,这个查询不起作用。我不知道如何让它工作,但我确实有一种感觉,这个查询可以更短。
最佳答案
试试这个:
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 did')
将返回1
或0
。因此,您只需将结果相加即可获得匹配项的数量。
关于php - SQL特定计数查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40061482/