我有如下查询。
SELECT Id, FIND_IN_SET('22', Category ) >0 AS `tot_cat`
FROM tbl_doctorprofile
我得到的结果是哪一行我得到的值'22'否则0 .. 所以结果如下。
Id tot_cat
----------
1 0
2 0
3 1
4 0
但我想只计算值为1的行数。
答案 0 :(得分:2)
所以只需对列进行总结:
CipherBuilder
或正式好一点:
SELECT SUM(FIND_IN_SET('22', Category ) >0) AS `tot_cat`
FROM tbl_doctorprofile
答案 1 :(得分:1)
试试这个:
SELECT Id,
COUNT(CASE WHEN FIND_IN_SET('22', Category ) > 0 THEN 1 END) AS `tot_cat`
FROM tbl_doctorprofile
答案 2 :(得分:1)
您可以使用以下查询,它必须帮助您
SELECT COUNT(1) FROM
(SELECT Id, FIND_IN_SET('22', Category ) >0 AS `tot_cat`
FROM tbl_doctorprofile ) t WHERE t.tot_cat!=0;
答案 3 :(得分:0)
你想要这个吗?
SELECT Id, FIND_IN_SET('22', Category ) >0 AS `tot_cat`
FROM tbl_doctorprofile
HAVING `tot_cat` = 1