Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- create table pessoa(
- id_pessoa integer not null,
- nome varchar not null,
- endereco varchar not null,
- primary key (id_pessoa)
- )
- create table cliente(
- id_cliente integer not null,
- cpf varchar(11) not null,
- data_nasc timestamp not null,
- nome varchar not null,
- primary key(id_cliente),
- foreign key(id_Cliente) references pessoa(id_pessoa)
- );
- create table venda(
- id_venda integer not null,
- data date not null,
- id_cliente integer not null,
- primary key(id_venda),
- foreign key(id_cliente) references pessoa(id_pessoa)
- );
- create table item_venda(
- id_venda integer not null,
- id_estoque integer not null,
- primary key(id_venda,id_estoque),
- foreign key(id_venda)references venda(id_venda),
- foreign key(id_estoque)references produto_estoque(id_estoque)
- );
- create table fornecedor(
- id_fornecedor integer not null,
- cnpj varchar(14) not null,
- primary key(id_fornecedor)
- );
- create table produto(
- id_produto integer not null,
- descricao varchar not null,
- preco double precision not null,
- id_fornecedor integer not null,
- primary key(id_produto),
- foreign key(id_fornecedor) references fornecedor(id_fornecedor)
- );
- create table produto_estoque(
- id_estoque integer not null,
- id_produto integer not null,
- primary key(id_estoque),
- foreign key(id_produto) references produto(id_produto)
- );
- insert into pessoa
- (id_pessoa, nome, endereco)
- values
- (1,'Luiz Fernando', 'Rua das flores'),
- (2,'Bruce Wayne1', 'Mansão Wayne'),
- (3,'Darth Vader', 'Força Negra'),
- (4, 'Yoda', 'Não ter'),
- (5, 'Obi wan Kenobi', 'Terra Venus'),
- (6, 'Barry Allen','Central city'),
- (7, 'Felicity Smoal', 'Star City'),
- (8,'Solomon Grundy','Cyrus Gold'),
- (9,'Clark Kent','Metropolis'),
- (10,'Ted Mosby','New York');
- insert into cliente (
- id_cliente, cpf, data_nasc)
- values
- (1, 66666666666, '25/03/1989'),
- (3, 99999999999, '12/05/1910'),
- (6, 8888888888, '12/05/1990'),
- (7, 8888888888, '12/10/1990'),
- (9, 33333333333, '05/05/1950');
- insert into fornecedor (
- id_fornecedor, cnpj)
- values
- (2, 66666666666),
- (4, 99999999999),
- (5, 8888888888),
- (8, 8888888888),
- (10, 33333333333);
- insert into produto (
- id_produto, descricao, preco, id_fornecedor)
- values
- (1, 'ESPADA', 39.60, 2),
- (2, 'Falconete', 12.60, 4),
- (3, 'TANQEE', 5000.03, 5),
- (4, 'KATANA', 12.56, 8),
- (5,'Alabarda', 200.30, 10),
- (6, 'Cotó', 156.98, 2),
- (7, 'Mangual', 58.90, 4),
- (8, 'Hauberk', 88.65, 2),
- (9, 'Estrela da Manhã', 66.58, 10);
- insert into venda (
- id_venda, id_cliente, data)
- values
- (1, 1, '15/05/2015'),
- (2, 3, '15/05/2015'),
- (3, 6, '15/05/2015'),
- (4, 7, '15/05/2015'),
- (5, 9, '15/05/2015'),
- (6, 1, '16/05/2015'),
- (7, 3, '17/05/2015'),
- (8, 6, '18/05/2015'),
- (9, 7, '19/05/2015'),
- (10, 9, '20/05/2015'),
- (11, 1, '18/05/2015'),
- (12, 3, '19/05/2015'),
- (13, 6, '15/06/2015'),
- (14, 7, '17/05/2015'),
- (15, 9, '18/05/2017'),
- (16, 1, '15/05/2017'),
- (17, 3, '15/05/2017'),
- (18, 6, '15/05/2017'),
- (19, 7, '15/05/2017'),
- (20, 9, '15/05/2017'),
- (21, 1, '16/05/2017'),
- (22, 3, '17/05/2017'),
- (23, 6, '18/05/2017'),
- (24, 7, '19/05/2017'),
- (25, 9, '20/05/2017'),
- (26, 1, '18/05/2017'),
- (27, 3, '19/05/2017'),
- (28, 6, '15/06/2017'),
- (29, 7, '17/05/2017'),
- (30, 9, '18/05/2017');
- insert into produto_estoque (
- id_produto, id_estoque)
- values
- (1, 1),
- (2, 2),
- (3, 3),
- (4, 4),
- (5, 5),
- (6, 6),
- (7, 7),
- (8, 8),
- (9, 9),
- (1, 10),
- (2, 11),
- (3, 12),
- (4, 13),
- (5, 14),
- (6, 15),
- (7, 16),
- (8, 17),
- (9, 18),
- (1, 19),
- (2, 20),
- (3, 21),
- (4, 22),
- (5, 23),
- (6, 24),
- (7, 25),
- (8, 26),
- (9, 27),
- (1, 28),
- (2, 29),
- (3, 30),
- (4, 31),
- (5, 32),
- (6, 33),
- (7, 34),
- (8, 35);
- insert into item_venda
- (id_venda, id_estoque)
- values
- (1,1),
- (2,2),
- (3,3),
- (4,4),
- (5,5),
- (6,6),
- (7,7),
- (8,8),
- (9,9),
- (1,10),
- (11,11),
- (11,12),
- (12,13),
- (13,14),
- (13,15),
- (15,16),
- (1,17),
- (9,18),
- (12,19),
- (12,20),
- (11,21),
- (1,22),
- (5,23),
- (6,24),
- (7,25),
- (10,26),
- (9,27),
- (12,28),
- (12,29),
- (13,30),
- (14,31),
- (15,32),
- (16,33),
- (17,34),
- (20,35);
- update cliente set nome='João Paulo da Silva Santos', cpf='95980001856' where id_cliente=1;
- update cliente set data_nasc='30/12/1998' where data_nasc='12/05/1910';
- update venda set id_cliente=3 where id_Cliente=6;
- update venda set id_Cliente=6 where id_cliente=9;
- update venda set id_Cliente=9 where id_cliente=3;
- update produto set preco=preco+preco*0.20 where id_produto=1;
- update produto set preco=preco-preco*0.30 where id_produto=3;
- update produto set preco=preco-preco*0.50 where id_fornecedor=8;
- update produto set preco=preco+preco*0.50 where id_fornecedor=4;
- delete from venda where id_venda in (1,4,6,9,11,14,16,19,21,24,26,29,5,10,15,20,25,30,2,7,12,17,22,27,3,8,13,18,23,28);
- select * from item_venda
- delete from item_venda where id_estoque in (1,3,4,5,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,27,28,29,30,31,32);
- select * from cliente
- delete from cliente where id_cliente in(6,7,9)
- delete from fornecedor where id_fornecedor in(2,4,6,8,10)
- select * from fornecedor
- select * from produto
- delete from produto where id_produto in(5,6,8,9,1,3,4,2,7)
- select * from produto_estoque
- delete from produto_estoque where id_estoque in (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)
- select * from pessoa
- delete from pessoa where id_pessoa in (1,2,3,4,5,6,7,8,9,10)
- 2 PARTE DESSA PORRA
- 4)
- select * from pessoa;
- select * from pessoa where nome ilike '%wa%';
- select * from venda where data between '2017-02-05' and '3000-02-05';
- select * from produto where preco between >= 4000;
- 5)
- a)select f.cnpj from fornecedor as f
- order by f.cnpj;
- b)select f.cnpj,p.nome from fornecedor as f
- inner join pessoa as p on f.id_fornecedor = p.id_pessoa
- order by f.cnpj, p.nome;
- c)select c.nome, p.endereco from cliente as c
- inner join pessoa as p on c.id_cliente = p.id_pessoa
- group by c.nome, p.endereco;
- d)select id_venda from venda
- e)select c.nome,v.id_venda from cliente as c
- inner join venda as v on id_cliente = id_venda
- group by c.nome, v.id_venda;
- f)select p.descricao from produto as p
- g)select
- h)select p.descricao from produto as p
- inner join produto_estoque as pe
- on id_produto = id_estoque
- inner join venda as v
- on id_estoque = id_venda
- group by p.descricao
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement