0

我正在使用以下查询成功连接两个表。我想添加仅显示具有至少 2 条 SearchPrice >= 250000 记录的代理的条件...我尝试添加“HAVING COUNT( ) >= 2”但是当我添加这个时我只得到一个结果?我认为它可能将“HAVING COUNT( ) >= 2”应用于 ActiveAgent 表?

    SELECT 
    r.EmailAddress AS ag_email, 
    e.ListingAgentFullName AS ag_name, 
    r.OfficeName AS ag_office_name 
    FROM RESI 
    e JOIN ActiveAgent r 
    ON e.ListingAgentNumber=r.MemberNumber
    WHERE SearchPrice >= 250000;
4

1 回答 1

1

试试这个

SELECT 
    r.EmailAddress AS ag_email, 
    COUNT(r.EmailAddress) AS `acount`,
    e.ListingAgentFullName AS ag_name, 
    r.OfficeName AS ag_office_name 
    FROM RESI 
    e LEFT JOIN ActiveAgent r 
    ON e.ListingAgentNumber=r.MemberNumber
    WHERE SearchPrice >= 250000;
    GROUP BY r.EmailAddress
    HAVING acount >=2
于 2013-10-23T16:40:34.690 回答