关系数据库是
employee(employee_name, street, city) works(employee_name company_name, salary) company(company_name, city) manages(employee_name, manager_name)
我需要找到所有与他们的经理住在同一条街道和城市的员工。我的代码如下:
select distinct employee_name from employee, company where employee.city = company.city;
任何建议或技巧都很好。
试试这个
SELECT e.employee_name FROM employee e JOIN manages m ON m.employee_name = e.employee_name WHERE EXISTS ( SELECT 1 FROM empoloyee WHERE employee_name = m.manager_name AND street = e.street AND city = e.city )