-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnorthwind1.sql
52 lines (43 loc) · 1.82 KB
/
northwind1.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
--vd1: Danh sách ID, Fullname, Country
select * from Employees
select EmployeeID, LastName + ' ' + FirstName as [FullName], Country, year(getdate()) - year(BirthDate) as [Age]
from Employees
where year(getdate()) - year(BirthDate) >= 70 AND Country = 'USA'
ORDER BY Age DESC
select Top(3) EmployeeID, LastName from Employees
--Vd4
Select CustomerID, CompanyName, ContactName, ContactTitle, Country from Customers where Country = 'UK'
--Vd5
Select CustomerID, CompanyName, Address, city, country from Customers where Country = 'Mexico'
--Vd6
Select CustomerID , CompanyName , phone, address, city, Country from Customers where Country = 'Sweden'
--vd7
Select ProductID , ProductName , UnitPrice , UnitsInStock from Products where UnitsInStock between 5 and 10
--vd8
Select *from Products where UnitsOnOrder between 60 and 100
SELECT EmployeeID, count(EmployeeID) FROM Orders GROUP BY YEAR(OrderDate)
--vd9
SELECT EmployeeID, LastName, FirstName, Title, YEAR(BirthDate), [total orders]
FROM Employees
--Declare syntax
DECLARE @MaxUnitstock AS int
SET @MaxUnitstock = (SELECT MAX(UnitsInStock) FROM Products)
PRINT @MaxUnitstock
--vd32
SELECT ProductID, ProductName, SupplierID, CategoryID, UnitsInStock
FROM Products
WHERE UnitsInStock = @MaxUnitstock --Ko dung duoc???
DECLARE @MinUS AS int = (SELECT MIN(UnitsInStock) FROM Products)
PRINT @MinUS
--vd33
SELECT ProductID, ProductName, SupplierID, CategoryID, UnitsInStock
FROM Products
WHERE UnitsInStock = @MinUS --Ko dung duoc ???
--vd34
SELECT ProductID, ProductName, SupplierID, CategoryID, UnitsOnOrder
FROM Products
WHERE UnitsOnOrder = (SELECT MAX(UnitsOnOrder) FROM Products)
--vd35
SELECT ProductID, ProductName, SupplierID, CategoryID, ReorderLevel
FROM Products
WHERE ReorderLevel = (SELECT MAX(ReorderLevel) FROM Products)