如何在两个表上使用联合 [英] how to use union on two tables
本文介绍了如何在两个表上使用联合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须在表中列出时间表和员工.
时间表表中包含employeeid,startdate,enddate列和
员工表包含employeeid,employeename列.
现在,如果我想知道在特定日期没有填写时间表的员工名称.
在此先感谢.
I have to tables name timesheet and employee.
where timesheet table contains employeeid,startdate,enddate columns and
employee table contains employeeid,employeename columns.
now if i want to know the employeename who has not fill the timesheet on a particular day.
Thanks in Advance.
推荐答案
首先,我想告诉您,无需使用UNION即可得到这样的结果.
您在这里解决方案:
Hi,
First of all i would like to tell you that no need to use UNION to get such result.
You Solution Here:
SELECT * FROM Employee WHERE EmployeeID NOT IN (SELECT EmployeeID FROM TimeSheet WHERE StartDate>='YYYY-MM-DD' AND EndDate<='YYYY-MM-DD')
Select e.employeename
from employee e join timesheet t
where e.employeeid=t.employeeid
and t.startdate is null
or t.enddate is null
嘿,
试试这个
Hey,
Try this
select employeename from employee emp inner join timesheet ts on emp.employeeid =ts.employeeid
where startdate=null or enddate=null
祝你好运
Good Luck
这篇关于如何在两个表上使用联合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文