-
Notifications
You must be signed in to change notification settings - Fork 0
/
2618 - Produtos Importados.sql
67 lines (53 loc) · 1.58 KB
/
2618 - Produtos Importados.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
CREATE DATABASE uri_problem_2618;
USE uri_problem_2618;
CREATE TABLE providers (
id numeric PRIMARY KEY,
name varchar(255),
street varchar(255),
city varchar(255),
state char(2)
);
CREATE TABLE categories (
id numeric PRIMARY KEY,
name varchar(255)
);
CREATE TABLE products (
id numeric PRIMARY KEY,
name varchar (255),
amount numeric,
price numeric,
id_providers numeric REFERENCES providers (id),
id_categories numeric REFERENCES categories (id)
);
INSERT INTO providers (id, name, street, city, state)
VALUES
(1, 'Ajax SA', 'Rua Presidente Castelo Branco', 'Porto Alegre', 'RS'),
(2, 'Sansul SA', 'Av Brasil', 'Rio de Janeiro', 'RJ'),
(3, 'South Chairs', 'Rua do Moinho', 'Santa Maria', 'RS'),
(4, 'Elon Electro', 'Rua Apolo', 'São Paulo', 'SP'),
(5, 'Mike Electro', 'Rua Pedro da Cunha', 'Curitiba', 'PR');
INSERT INTO categories (id, name)
VALUES
(1, 'Super Luxury'),
(2, 'Imported'),
(3, 'Tech'),
(4, 'Vintage'),
(5, 'Supreme');
INSERT INTO products (id, name, amount, price, id_providers, id_categories)
VALUES
(1, 'Blue Chair', 30, 300.00, 5, 5),
(2, 'Red Chair', 50, 2150.00, 2, 1),
(3, 'Disney Wardrobe', 400, 829.50, 4, 1),
(4, 'Blue Toaster', 20, 9.90, 3, 1),
(5, 'TV', 30, 3000.25, 2, 2);
/* Execute this query to drop the tables */
-- DROP TABLE products, categories, providers; --
/*Resolução do Exercício*/
SELECT p1.name, p2.name, c.name
FROM products p1
inner join providers p2
on p2.id = p1.id_providers
inner join categories c
on p1.id_categories = c.id
where p2.name = 'Sansul SA' and c.name = 'Imported'
;