about summary refs log tree commit diff
path: root/usth/ICT2.5/practical/2.sql
blob: 23cbf4b6c2b0d3fb8242482b0e9166e30046e7ba (plain) (blame)
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
SOURCE mywind/northwind-default-current-timestamp.sql;
SOURCE mywind/northwind-data.sql;

SELECT *
FROM products
WHERE discontinued=1;

SELECT *
FROM products
ORDER BY list_price
LIMIT 4;

SELECT id, product_name, list_price
FROM products
WHERE list_price
BETWEEN 15 AND 25;

SELECT id, CONCAT(first_name, ' ', last_name) AS name
FROM employees;

SELECT id, first_name, last_name
FROM employees
WHERE first_name LIKE 'A%';

SELECT COUNT(DISTINCT city) AS 'number of different cities'
FROM employees;

SELECT DISTINCT ship_name
FROM orders;

SELECT MIN(list_price), MAX(list_price)
from products;

SELECT COUNT(id) AS 'number of current products'
FROM products
WHERE discontinued=0;

SELECT AVG(list_price), STD(list_price)
FROM products;

SELECT product_name, list_price
FROM products
WHERE list_price > (SELECT AVG(list_price) FROM products);

INSERT INTO suppliers (company, last_name, first_name, city, country_region)
VALUES ('Habeco', 'Nguyễn', 'Hồng Linh', 'Hanoi', 'Vietnam');

INSERT INTO products (
  supplier_ids,
  product_code,
  product_name,
  list_price,
  discontinued,
  category)
VALUES (
  (SELECT id FROM suppliers WHERE company='Habeco'),
  'TB',
  'Truc Bach',
  22,
  0,
  'Beverages');

UPDATE products
SET standard_cost=18
WHERE product_name='Truc Bach';

DELETE
FROM suppliers
WHERE company='Habeco';