如何显示两个表中的数据

如何显示两个表中的数据

本文介绍了如何显示两个表中的数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,
我有2个表部门(具有列depID和Departmentname)和雇员(具有列EmpID,Emp_name,DepID1,DepID2).
我的结果表为
EmpID,Emp_name,部门名称,部门名称
我需要给我上面的结果表的查询.
解释我的查询
我想要的是类似于员工表的结果,但是dep_id1,dep_id2应该替换部门表中的相应部门名称.
假设某员工属于两个部门,那么
我需要结果为
empid,empname,departmentname,departmentname

Hi all,
I have 2 tables department(with columns depID and Departmentname)and employee(with columns EmpID,Emp_name,DepID1,DepID2).
I resultant table as
EmpID,Emp_name,Departmentname,Departmentname
i need the query which gives me above resultant table.
Explain my query
what i want is a result which is similar to employee table but the dep_id1, dep_id2 should replaced wit respective departmentname from department table.
Suppose an employee belongs to 2 departments then
i need the result as
empid,empname,departmentname, departmentname

推荐答案

select E.EmpID, E.Emp_Name, d1.DepartmentName, d2.DepartmentName from Employee e inner join department d1 on e.DepID1 = d1.DepID inner join department d2 on e.depID2 = d2.DepID




您应该购买一本基本的SQL书籍并阅读.




You should buy a basic SQL book and read it.


这篇关于如何显示两个表中的数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-06 03:19