SQL视图创建
比如我有两个表
一个employee 一个department
employee表中有employeeid,name,email,deptid
department表中有deptid,deptname,daptname,managerid
我现在创建这两个表的视图,要求视图中包含
employeeid,name,email,managername,manageremail
前三个能直接勾选,后两个该怎么做啊,只知道通过employee表与department表结合能得到managername和managermail
但是怎么放在视图中呢?
求解!!第一次做视图....
[解决办法]
select 查找字段 from employee e inner join department d
on e.deptid=p.deptid ,email,managername,manageremail这些在哪个表呀,就是关联查询
[解决办法]
就是两表关联查询 通过deptid关联
你把第一个表拖进到视图当中 可以勾选 ,第二个表的字段 当然也可以勾选啊 主要还是通过deptid关联
[解决办法]
如果department.managerid来自表employee.employeeid的话create view view_employeeas select a.employeeid,a.name,a.email,b.name as managername ,b.email as manageremailfrom employee a left join department d on a.deptid = d.deptidleft join employee b on d.managerid = b.employeeid
[解决办法]
CREATE VIEW dbo.view_employee_departmentASselect employeeid,name,emailfrom employeeUNIONselect name as managename,email as manegeemail from employee a left join department b on a.deptid=b.deptid
[解决办法]