0

我正在运行以下查询:

SELECT *, COUNT(iup.user_id) AS user_plans_count
FROM #__iop_user_plans iup
INNER JOIN #__iop_plan ip ON iup.iop_id = ip.id
WHERE `iup`.`state` = 1 AND `iup`.`user_id` IS NOT NULL AND `iup`.`accepted` = 0

当没有适用的行时,MySQL 仍然返回一个只包含计数的结果。如何更改我的查询以仅返回大于 0 的计数?

4

1 回答 1

2

这将完成这项工作

SELECT *, COUNT(iup.user_id) AS user_plans_count
FROM #__iop_user_plans iup
INNER JOIN #__iop_plan ip ON iup.iop_id = ip.id
WHERE `iup`.`state` = 1 AND `iup`.`user_id` IS NOT NULL 
AND `iup`.`accepted` = 0 
HAVING user_plans_count>0
于 2013-09-10T08:38:01.527 回答