-
Notifications
You must be signed in to change notification settings - Fork 0
/
02_02-WHERE.sql
55 lines (42 loc) · 1.26 KB
/
02_02-WHERE.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
-- equals
SELECT *
FROM Warehouse.StockItems
WHERE StockItemName = 'Chocolate sharks 250g'
-- like
SELECT *
FROM Warehouse.StockItems
WHERE StockItemName like 'Chocolate%'
-- index scan
SELECT *
FROM Warehouse.StockItems
WHERE StockItemName like '%250g'
-- как сделать, чтобы использовалс¤ индекс, если нужно часто делать такие запросы?
SELECT *
FROM Warehouse.StockItems
WHERE StockItemName like 'Chocolate%250g'
-- AND, OR
-- нужно вывести StockItems, где цена 350-500 и
-- название начинаетс¤ с USB или Ride.
-- ¬се правильно?
SELECT RecommendedRetailPrice, *
FROM Warehouse.StockItems
WHERE
RecommendedRetailPrice BETWEEN 350 AND 500 AND
StockItemName like 'USB%' OR
StockItemName like 'Ride%'
-- ‘ункции в WHERE
DROP INDEX IF EXISTS IX_Sales_Orders_OrderDate ON Sales.Orders
SELECT *
FROM Sales.Orders o
WHERE year(OrderDate) = 2013
SELECT *
FROM Sales.Orders o
WHERE OrderDate = '2013-01-01'
CREATE INDEX IX_Sales_Orders_OrderDate ON Sales.Orders(OrderDate)
SELECT *
FROM Sales.Orders o
WHERE year(OrderDate) = 2013
SELECT *
FROM Sales.Orders o
WHERE OrderDate = '2013-01-01'
DROP INDEX IX_Sales_Orders_OrderDate ON Sales.Orders