-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathData_Query_Language_DQL_2.sql
More file actions
40 lines (28 loc) · 1.6 KB
/
Data_Query_Language_DQL_2.sql
File metadata and controls
40 lines (28 loc) · 1.6 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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
---First thing we will do is to simply select everything from a table
select * from HumanResources.Employee
--Now we want to select columns from the same table.
select BusinessEntityID, JobTitle, BirthDate, MaritalStatus, Gender, HireDate, SalariedFlag, VacationHours, SickLeaveHours
from HumanResources.Employee
---Now Let's start using some conditions--
select BusinessEntityID, JobTitle, BirthDate, MaritalStatus, Gender, HireDate, SalariedFlag, VacationHours, SickLeaveHours
from HumanResources.Employee
where BusinessEntityID = 1 --mathematical operator
select BusinessEntityID, JobTitle, BirthDate, MaritalStatus, Gender, HireDate, SalariedFlag, VacationHours, SickLeaveHours
from HumanResources.Employee
where BusinessEntityID IN (10, 15, 20) ---logical operators
--We want employees with more than 2 weeks vacations
--40 hrs = 1 week
--80 hrs = 2 weeks of vacation
select BusinessEntityID, JobTitle, BirthDate, MaritalStatus, Gender, HireDate, SalariedFlag, VacationHours, SickLeaveHours
from HumanResources.Employee
where VacationHours > 80
---Employees with less or equal to 80 hrs of vacation and are single
select BusinessEntityID, JobTitle, BirthDate, MaritalStatus, Gender, HireDate, SalariedFlag, VacationHours, SickLeaveHours
from HumanResources.Employee
where VacationHours <= 80
AND MaritalStatus = 'S'
---Employees with less or equal to 80 hrs of vacation or are single
select BusinessEntityID, JobTitle, BirthDate, MaritalStatus, Gender, HireDate, SalariedFlag, VacationHours, SickLeaveHours
from HumanResources.Employee
where VacationHours <= 80
OR MaritalStatus = 'S'