限制一对多关系中的行数?

时间:2015-04-16 11:04:24

标签: sql postgresql

我有以下查询:

SELECT address.addressid,
       employee.employeeid
FROM employee,
     address
WHERE address.employeeid = employee.employeeid;

产生以下输出:

Output

现在我想限制行,说只有两个以上地址的员工才会被查询显示。我如何实现这一目标?

1 个答案:

答案 0 :(得分:0)

select address.addressid,
       employee.employeeid
from employee,
     address
where address.employeeid = employee.employeeid
group by employee.employeeid
having count(address.employeeid) > 2