你好我在我的sql代码中计数count(返回= 0)时遇到了一些麻烦。
SELECT `return`
FROM `numbers`
WHERE list_id IN (
SELECT id from listy where listy.number = "900000335300000939680320"
)
以下是一个示例,如何使用此确切查询对return = 0
进行计数。
答案 0 :(得分:3)
当然,您需要在查询中使用COUNT()
,并添加AND
以仅查看return = 0
的行。
SELECT COUNT(`return` ) AS returncount
FROM `numbers`
WHERE list_id IN (
SELECT id from listy where listy.number = "900000335300000939680320"
) AND
`return` = 0
答案 1 :(得分:2)
SELECT count(*)
FROM `numbers`
WHERE list_id IN (SELECT id
from listy
where listy.number = "900000335300000939680320")
AND `return` = 0;
答案 2 :(得分:1)
答案 3 :(得分:0)
在AND
之后使用WHERE
子句缩小结果(最后一行),而不是计算你有多少SELECT COUNT()
:
SELECT COUNT(return)
FROM numbers
WHERE list_id IN (
SELECT id from listy where listy.number = "900000335300000939680320"
)
AND return = 0
答案 4 :(得分:0)
这可能会对您有所帮助:
SELECT `return`,count(*) FROM `numbers` n join `listy` l
on n.list_id = l.id
where l.number = "900000335300000939680320"
and n.return = 0
group by `return`