gpt4 book ai didi

mysql - MySql中如何连接多个条件表

转载 作者:行者123 更新时间:2023-11-29 11:29:32 25 4
gpt4 key购买 nike

我有perf_component_valuation表:
enter image description here

然后我加入:

SELECT CONCAT(ee.first_name,' ',ee.last_name) as valuated_name,CONCAT(ee.first_name,' ',ee.last_name) as valuator_name from emp_employee as ee 
left join perf_component_valuation as pcv on pcv.valuator=ee.employee_id
WHERE pcv.phc_id =49;

试试这个:

SELECT CONCAT(ee.first_name,' ',ee.last_name) as valuated_name,CONCAT(ee.first_name,' ',ee.last_name) as valuator_name from emp_employee as ee 
left join perf_component_valuation pcv on pcv.valuator=ee.employee_id
left join perf_component_valuation pcv2 on pcv2.valuated=ee.employee_id
WHERE pcv.phc_id =49;

但它只给我评估者姓名,而不是评估。这就是结果:

enter image description here

我想要的结果是:

valuated_name || valuator_name
______________________________
Adni || Arli Ramdhani
Adni || Mohammad Aldo


我如何给出另一个条件?

最佳答案

尝试加入 emp_employee 两次

SELECT CONCAT(valuated_ee.first_name,' ',valuated_ee.last_name) as valuated_name,CONCAT(valuator_ee.first_name,' ',valuator_ee.last_name) as valuator_name 
from perf_component_valuation as pcv
left join emp_employee as valuated_ee on pcv.valuated=valuated_ee.employee_id
left join emp_employee as valuator_ee on pcv.valuator=valuator_ee.employee_id
WHERE pcv.phc_id =49;

关于mysql - MySql中如何连接多个条件表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37649220/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com