Advertisement
Guest User

Untitled

a guest
Dec 1st, 2018
127
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.29 KB | None | 0 0
  1. create table Fornecedor(
  2. id_forn integer(10) not null,
  3. nome_forn varchar(24) not null,
  4. endereco_forn varchar(30) not null,
  5. cnpj_forn integer(18) not null,
  6. dataReceb_forn date not null,
  7. constraint id_forn_pk primary key (id_forn));
  8.  
  9. create table Ingrediente(
  10. id_ingr integer(10) not null,
  11. nome_ingr varchar(24) not null,
  12. quantidade_ingr integer(5) not null,
  13. constraint id_ingr_pk primary key (id_ingr));
  14.  
  15. create table Esfiha(
  16. id_esf integer(10) not null,
  17. nome_esf varchar(20) not null,
  18. sabor_esf varchar(16) not null,
  19. preco_esf integer(4.2) not null,
  20. constraint id_esf_pk primary key (id_esf));
  21.  
  22. create table Funcionario(
  23. id_func integer(10) not null,
  24. nome_func varchar(24) not null,
  25. telefone_func integer(12) not null,
  26. doc_func integer(18) not null,
  27. email_func varchar(30) not null,
  28. endereco_func varchar(50) not null,
  29. constraint id_func_pk primary key (id_func));
  30.  
  31. create table Cliente(
  32. id_cli integer(10) not null,
  33. nome_cli varchar(24) not null,
  34. telefone_cli integer(12) not null,
  35. endereco_cli varchar(50) not null,
  36. form_pagamento varchar(12) not null,
  37. constraint id_cli_pk primary key (id_cli));
  38.  
  39. create table Venda(
  40. id_venda integer(10) not null,
  41. id_cliente integer(10) not null,
  42. id_funcionario integer(10) not null,
  43. id_esfiha integer(10) not null,
  44. preco integer(4.2) not null,
  45. dt_venda date not null,
  46. constraint venda_pk primary key(id_venda),
  47. constraint cli_fk foreign key (id_cliente) references Cliente(id_cli),
  48. constraint func_fk foreign key(id_funcionario) references Funcionario(id_func),
  49. constraint esf_fk foreign key(id_esfiha) references Esfiha(id_esf));
  50.  
  51. insert into Fornecedor values(1, 'Gabriel', 'Avenida Paulista', '275', date '2018-11-03');
  52. insert into Fornecedor values(2, 'Pedro', 'Vila Carrão', '41410', date '2018-10-24');
  53. insert into Fornecedor values(3, 'Lucas', 'Sapopemba', '82820', date '2018-11-30');
  54.  
  55. insert into Ingrediente values(1, 'Presunto', 30);
  56. insert into Ingrediente values(2, 'Queijo', 5);
  57. insert into Ingrediente values(3, 'Calabresa', 17);
  58.  
  59. insert into Esfiha values(1, 'Especial', 'Tudo', 40);
  60. insert into Esfiha values(2, 'Padrao', 'Carne e Queijo', 5);
  61. insert into Esfiha values(3, 'Moda da Casa', 'Frango com Ched.', 35);
  62.  
  63. insert into Funcionario values(1, 'Jose', 40028922, 329328, 'josepastel@hotmail.com', 'Rio de Janeiro');
  64. insert into Funcionario values(2, 'Wilson', 80416844, 95283, 'wilsonotario@gmail.com', 'Acre');
  65. insert into Funcionario values(3, 'Douglas', 6844324, 749043, 'douglas123@gmail.com', 'Rio Grande do Sul');
  66.  
  67. insert into Cliente values(1, 'Josnildo', 123, 'Rua da Banana', 'Dinheiro');
  68. insert into Cliente values(2, 'Josefino', 246, 'Rua da Goiaba', 'Cartao');
  69. insert into Cliente values(3, 'Jorgescleyson', 4812, 'Rua do Abacate', 'Cheque');
  70.  
  71. insert into Venda values(1, 1, 1, 1, 50, date '2018-12-01');
  72. insert into Venda values(2, 2, 2, 2, 80, date '2018-11-30');
  73. insert into Venda values(3, 3, 3, 3, 30, date '2018-09-17');
  74.  
  75. select sabor_esf as Esfiha, preco_esf as Preço from Esfiha;
  76. select sabor_esf as Esfiha, preco_esf as Preço from Esfiha where preco_esf > 30;
  77. select nome_cli as Cliente, endereco_cli as Endereço from Cliente;
  78. select count(*) as Total_de_Vendas from Venda;
  79. select count(quantidade_ingr) as Total_de_Ingredientes from Ingrediente;
  80. select count(nome_func) as Total_de_Funcionarios from Funcionario;
  81. select count(nome_forn) as Total_de_Fornecedores from Fornecedor;
  82. select nome_forn as Fornecedor, cnpj_forn as CNPJ from Fornecedor;
  83. select nome_func as Funcionario, doc_func as Documento from Funcionario;
  84. select nome_func as Funcionario, endereco_func as Endereço from Funcionario where endereco_func = 'Rio de Janeiro';
  85. select nome_cli as Cliente, form_pagamento as Pagamento from Cliente where form_pagamento = 'Dinheiro';
  86. select nome_ingr as Ingrediente, quantidade_ingr as Quantidade from Ingrediente where nome_ingr = 'Presunto';
  87. select nome_ingr as Ingrediente, quantidade_ingr as Quantidade from Ingrediente where quantidade_ingr > 5;
  88. select nome_forn as Fornecedor, dataReceb_forn as Recebimento from Fornecedor where month(dataReceb_forn) = month(current_date()- interval 1 month);
  89.  
  90. select Cliente.nome_cli as Cliente, sabor_esf as Sabor, sum(Esfiha.preco_esf)
  91. as Preço
  92. from Cliente
  93. inner join Esfiha on Cliente.id_cli = Esfiha.id_esf
  94. group by Cliente.nome_cli, sabor_esf;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement