-
Notifications
You must be signed in to change notification settings - Fork 0
/
bai_thuc_hanh_1.sql
66 lines (65 loc) · 1.26 KB
/
bai_thuc_hanh_1.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
-- #1
SELECT
Title, FirstName, MiddleName, LastName
FROM
Person.Person;
-- #2
SELECT
ISNULL(Title, '') + ' ' + FirstName + ' ' + LastName AS PersonName
FROM
Person.Person;
-- #3
SELECT
AddressLine1 + ' ' + ISNULL(AddressLine2, '') AS AddressLine, City
FROM
Person.Address;
-- #4
SELECT DISTINCT City
FROM
Person.Address;
-- #5
SELECT TOP 10
*
FROM Person.Address;
-- #6
SELECT AVG(Rate) AS AverageRate
FROM HumanResources.EmployeePayHistory;
-- #7
SELECT COUNT(*) AS #Employees
FROM HumanResources.Employee;
-- #8
WITH
SalesPerCustomer
AS
(
SELECT
c.CustomerID,
NumberOfSales = COUNT(soh.SalesOrderID)
FROM
Sales.Customer c
INNER JOIN
Sales.SalesOrderHeader soh ON soh.CustomerID = c.CustomerID
GROUP BY
c.CustomerID
)
SELECT
p.FirstName + ' ' + p.LastName AS CustomerName,
spc.NumberOfSales
FROM
SalesPerCustomer spc
JOIN
Person.Person p ON p.BusinessEntityID = spc.CustomerID
WHERE
spc.NumberOfSales > 10;
-- #9
SELECT
Name
FROM
Production.Product
WHERE ProductID NOT IN (
SELECT ProductID
FROM
Sales.SalesOrderDetail
);
-- #10
-- #11