-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSQLTASK1-4.sql
201 lines (146 loc) · 4.53 KB
/
SQLTASK1-4.sql
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
use AdventureWorks2014
--Query1
select FirstName,LastName
from Person.Person
where Title is not null
--Query2
select FirstName,LastName
from Person.Person
where FirstName like '%a' or LastName like '%a'
--Query3
select cur.CurrencyCode,Name
from Sales.Currency cur
join Sales.CountryRegionCurrency coun
on cur.CurrencyCode=coun.CurrencyCode
--Query4
select * into HR_dept
from HumanResources.Department
select * from HR_dept
--Query5
create table Tbl_1
(
Sno int identity(1,1),
FName varchar(20),
LName varchar(20),
Gender varchar(10),
MobileNo varchar(20)
)
insert into Tbl_1
values('Anandha','Kumar','M','9962714878')
insert into Tbl_1
values('Adesh','K','M','9962714578')
insert into Tbl_1
values('Harish','A','M','9962714878')
insert into Tbl_1
values('Thangam','K','F','9962714878')
insert into Tbl_1
values('Mugesh','Raj','M','9962714878')
insert into Tbl_1
values('Isaac','samuel','M','9962714878')
insert into Tbl_1
values('arjun','sathish','M','9962714878')
insert into Tbl_1
values('john','ricky','M','9962714878')
insert into Tbl_1
values('venkat','sidd','M','9962714878')
insert into Tbl_1
values('giri','dharan','M','9962714878')
insert into Tbl_1
values('Ajay','Kanna','M','9962714878')
insert into Tbl_1
values('Harish','war','M','9962714878')
insert into Tbl_1
values('Abdul','A','M','9962714878')
insert into Tbl_1
values('Dinesh','Kumar','M','9962714878')
insert into Tbl_1
values('Dinesh','J','M','9962714878')
insert into Tbl_1
values('deepak','K','M','9962714878')
insert into Tbl_1
values('Balaji','R','M','9962714878')
insert into Tbl_1
values('koushik','K','M','9962714878')
insert into Tbl_1
values('santhosh','Kumar','M','9962714878')
insert into Tbl_1
values('Surya','P','M','9962714878')
select * from Tbl_1
--Query6
select BusinessEntityID,AddressTypeID
from Person.BusinessEntityAddress
--Query7
select distinct GroupName
from HumanResources.Department
--Query8
select PCH.standardcost, sum(listprice) Lstprice,sum(PCH.standardcost) Stdcost
from Production.Product PCH
join Production.ProductCostHistory prod
on PCH.ProductID=prod.ProductID
group by PCH.StandardCost
--Query9
select DATEDIFF(YY,startdate,EndDate) as Yearsonrole
from HumanResources.EmployeeDepartmentHistory
--Query10
select sum(salesquota) SalesQuota
from sales.SalesPersonQuotaHistory
where SalesQuota>5000 and SalesQuota<100000
group by SalesQuota
--Query11
select max(TaxRate) as Max_taxrate
from Sales.SalesTaxRate
--Query12
select dept.DepartmentID,emp.BusinessEntityID,ShiftID,BirthDate
from HumanResources.Employee emp
join HumanResources.EmployeeDepartmentHistory depth
on emp.BusinessEntityID=depth.BusinessEntityID
join HumanResources.Department dept
on dept.DepartmentID=depth.DepartmentID
select birthdate,getdate() as currentdate,datediff(YY,birthdate,getdate()) as age
from HumanResources.Employee
--Query13
create view Nameage
as
select birthdate,getdate() as currentdate,datediff(YY,birthdate,getdate()) as age
from HumanResources.Employee
go
select * from Nameage
--Query14
select count(*) as noofrows
from HumanResources.Employee,HumanResources.EmployeeDepartmentHistory,HumanResources.EmployeePayHistory,HumanResources.JobCandidate
--Query15
select max(rate) as Maxsalary,Name
from HumanResources.EmployeePayHistory pay
join HumanResources.EmployeeDepartmentHistory dhis
on pay.BusinessEntityID=dhis.BusinessEntityID
join HumanResources.Department dept
on dept.DepartmentID=dhis.DepartmentID
group by Name
--Query16
select FirstName,MiddleName,Title,AddressTypeID,Busen.BusinessEntityID
from Person.Person per
left join person.BusinessEntityAddress BusEn
on per.BusinessEntityID=Busen.BusinessEntityID
where Title is not null
--Query17
select ProductID,LocationID,Shelf
from Production.ProductInventory
where ProductID>300 and ProductID<350 and Shelf='E'
--Query18
select prod.LocationID,Shelf,Name
from production.ProductInventory prod
join Production.Location loc
on prod.LocationID=loc.LocationID
--Query19
select AddressID,AddressLine1,AddressLine2,sta.StateProvinceID,StateProvinceCode,CountryRegionCode
from person.StateProvince sta
join Person.Address ad
on sta.StateProvinceID=ad.StateProvinceID
--Query20
select sum(SubTotal),sum(TaxAmt)
from sales.CountryRegionCurrency orr
join sales.SalesTerritory ter
on orr.CountryRegionCode=ter.CountryRegionCode
join sales.SalesOrderHeader coun
on ter.TerritoryID=coun.TerritoryID
group by ter.TerritoryID