-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSet Operators.sql
More file actions
25 lines (20 loc) · 1.09 KB
/
Set Operators.sql
File metadata and controls
25 lines (20 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
---Set operators
---just assuming i am given 2 different data set and given instruction to find the out
---1)The employee who had done transaction on 30th of november and december = union
---2)The employee who had done transaction on both the months on the 30th day. = intersect
---3)The employee who had done transaction on 30th but not in the month of november and december = except
select e.Emp_id,e.EmpFirstName,e.EmpLastname,d.Dept_Name,t.DateOfTransaction
from Employee as e
left join Department as d
on d.Dept_Name = e.Department
left join EmpTransaction as t
on e.Emp_id = t.Emp_id
where t.DateOfTransaction in (select DateOfTransaction from EmpTransaction where datepart(DAY,DateOfTransaction) = 30)
except--/union all/intersect/union
select e.Emp_id,e.EmpFirstName,e.EmpLastname,d.Dept_Name,t.DateOfTransaction
from Employee as e
left join Department as d
on d.Dept_Name = e.Department
left join EmpTransaction as t
on e.Emp_id = t.Emp_id
where t.DateOfTransaction in(select DateOfTransaction from EmpTransaction where datepart(month,DateOfTransaction) in (11,12))