我有两张桌子
“雇主”:
emp_id empl_name wage
1 john 20/h
2 mike 20/h
3 sam 30/h
“职位”:
pos_id emp_id pos_name related_pos
1 1 cleaner 0
2 3 driver 3
3 2 bodyguard 0
我需要显示表,其中包含雇主名称、职位名称、工资、相关职位名称、Rel Pos 工资、Rel Pos 雇主
现在我有查询:
SELECT pos_name, empl_name, wage
FROM positions
LEFT JOIN employers ON employers.emp_id = positions.emp_id
下一个 rquest 不起作用,但给出了我需要的想法:
SELECT pos_name, empl_name, wage, (SELECT empl_name
FROM positions
LEFT JOIN employers ON employers.emp_id = positions.related_pos) as emp2,
(SELECT pos_name
FROM positions
WHERE pos_id = related_pos) as pos2
FROM positions
LEFT JOIN employers ON employers.emp_id = positions.emp_id