0

所以我做了一个简单的查询,给出了提到 PassportNumber = 'C_AA8' 的案例总数。但是,如果我为 RegistrationCase 中不存在的 PassportNumber 设置查询,它将返回 0(据我所知,它不能加入)。我该如何解决?并且有一种方法可以重新制作此查询以与 GROUP BY 一起使用?感谢您提供任何进一步的帮助。我正在将 MySQL 与 PHPmyadmin 和 AMPPS 一起使用。固定寄存器。

SELECT COUNT( unRegisterCase.PassportNumber ) + COUNT( RegistrationCase.PassportNumber ) + COUNT( RecoveringCase.NewPassportNumber ) AS result
FROM RegistrationCase
LEFT JOIN unRegisterCase ON unRegisterCase.PassportNumber = RegistrationCase.Passportnumber
LEFT JOIN RecoveringCase ON RecoveringCase.NewPassportNumber = RegistrationCase.Passportnumber
WHERE RegistrationCase.PassportNumber =  'C_AA8'
4

2 回答 2

1

不是吗?

SELECT COUNT(PassportNumber ) as PassportCount FROM
(
SELECT PassportNumber FROM RegistrationCase UNION ALL
SELECT NewPassportNumber FROM RecoveringCase UNION ALL
SELECT PassportNumber FROM unRegisterCaseber
) A
WHERE PassportNumber =  'C_AA8'
于 2012-12-27T17:32:55.517 回答
0

以及 SQl 底部的 where 子句,它取消了左连接,

试试这个

 SELECT COUNT( UnregisterCase.PassportNumber ) + 
        COUNT( RegistrationCase.PassportNumber ) + 
        COUNT( RecoveringCase.NewPassportNumber ) AS result
 FROM RegistrationCase, unRegisterCase, RecoveringCase
 WHERE UnregisterCase.PassportNumber = RegistrationCase.Passportnumber
 AND RecoveringCase.NewPassportNumber = RegistrationCase.Passportnumber
 AND RegistrationCase.PassportNumber =  'C_AA8'

还要检查是否区分大小写,因为 unRegister 和 Unregister 的拼写不同

于 2012-12-27T17:27:37.507 回答