用于将四个表链接在一起的SQL JOIN查询

时间:2017-01-12 15:15:06

标签: sql join

显示员工姓名,工资以及他们为未在意大利运营部门工作的IT开发人员所工作的城市名称

我做了这个

SELECT e.first_name,e.last_name,e.salary,l.city
FROM employees e join jobs j
ON(j.job_id = e.job_id)
WHERE AND e.commission_pct = 0 AND 
job_title LIKE '%IT Developer%'

join locations l 
ON (l.location_id = d.location_id)
AND (l.country LIKE '%Italy%'
AND department_name = 'Operations');

2 个答案:

答案 0 :(得分:0)

您是否询问查询为何无效?您的加入语法不正确。它应该如下所示:

SELECT  e.first_name
    ,   e.last_name
    ,   e.salary
    ,   l.city
FROM    employees e join jobs j      ON (j.job_id = e.job_id)
                    join locations l ON (l.location_id = d.location_id)
WHERE e.commission_pct = 0
AND job_title LIKE '%IT Developer%'
AND (l.country LIKE '%Italy%'
AND department_name = 'Operations');

答案 1 :(得分:0)

也许这个?

SELECT 
    e.first_name,
    e.last_name,
    e.salary,
    l.city
FROM employees e join jobs j
ON(j.job_id = e.job_id)
JOIN locations l 
    ON (l.location_id = d.location_id)
    AND (l.country LIKE '%Italy%'
    AND department_name = 'Operations')
WHERE e.commission_pct = 0 
AND job_title LIKE '%IT Developer%'