7

这是我的代码:

$sqlz = "SELECT t1.user_id, t2.status, t2.email 
         FROM coverages t1 
         LEFT JOIN users t2 ON t1.user_id = t2.user_id 
         GROUP BY t1.user_id  
         HAVING COUNT(t1.user_id) =".$value;

我想添加这个“ WHERE users.email IS NOT NULL”当我添加它时,它返回一个白页/没有结果。我知道事实上数据库上至少有 200 个结果包含电子邮件并且符合该标准。

这是我所做但不起作用的示例:

 $sqlz =    "SELECT t1.user_id, t2.status, t2.email 
             FROM coverages t1 
             LEFT JOIN users t2 ON t1.user_id = t2.user_id
             WHERE users.email IS NOT NULL 
             GROUP BY t1.user_id  
             HAVING COUNT(t1.user_id) =".$value;
4

1 回答 1

20

我认为您需要使用t2( alias ) 而不是users.

 $sqlz =    "SELECT t1.user_id, t2.status, t2.email 
             FROM coverages t1 
                     LEFT JOIN users t2 ON t1.user_id = t2.user_id
             WHERE t2.email IS NOT NULL 
             GROUP BY t1.user_id  
             HAVING COUNT(t1.user_id) = " .$value;
于 2012-07-02T00:40:44.517 回答