SlideShare ist ein Scribd-Unternehmen logo
1 von 5
Downloaden Sie, um offline zu lesen
Resolução da Ficha nº4


          1. Abra o xamp

          2. Cria uma base de dados (nome: Drogaria), com as seguintes tabelas:

             CREATE DATABASE Drogaria;




                                    Criar Tabelas :


CREATE TABLE Fornecedores( CodFornecedor int(10); Nome varchar (30), Morada
varchar (18), Telefone int (9), NrContribuinte int (10));

CREATE TABLE Artigos (CodArtigo int (10), Artigo varchar(10), preco varchar(10),
CodFornecedor int (10));

CREATE TABLE Clientes( CodigoCliente int (10), Nome varchar (10), Morada varchar
(10), Telefone int (10), NrContribuinte int (10));


                                              1
CREATE TABLE Encomendas( NrEncomendas int(10), Data int(10), CodCliente int(10),
CodArtigo int(10), Quantidade int (10));



          3. De seguida preencha a tabela com os seguintes dados:




                                 Inserir dados:


INSERT INTO Artigos ( CodArtigo, Artigo, Preco, CodFornecedor)
VALUES( A01, Alicate X, 2,15€, F101);
             Nota * : Para inserir o resto dos dados é sempre igual




                                 Inserir dados:


INSERT INTO Clientes ( CodigoCliente, Nome, Morada, Telefone, NrContribuinte)
VALUES (C111, Antunes, Aveiro, 234456456,235234534)
             Nota * : Para inserir o resto dos dados é sempre igual

                                         2
Inserir dados:


INSERT INTO Fornecedore (CodFornecedor,Nome,Morada,Telefone,NrContribuinte)
VALUES(F101,Coimbrox,Coimbre,234456456,234567890);

             Nota * : Para inserir o resto dos dados é sempre igual




                                Inserir dados:

INSERT INTO Encomendas ( NrEncomenda, Data, CodCliente, CodArtigo, Quantidade)
VALUES (1, 02-12-2005, C111,A01,10);

             Nota * : Para inserir o resto dos dados é sempre igual




                                       3
a) Mostrar todos os registos da tabela Artigos.

  SELECT * FROM Artigos;

b) Mostrar apenas o nome do artigo e o preço de todos os artigos.

   SELECT Nome, Preco FROM Artigos;

c) Mostrar os artigos que têm preço inferior a 3.

  SELECT * FROM Artigos WHERE Preco<3;

d) Mostrar apenas o nome do artigo e o preço dos artigos com preço menor que 3.

  SELECT Nome, Preco FROM Artigos WHERE Preco<3;

e) Mostrar apenas o nome do artigo e o preço dos artigos com preço entre 2 e 3 inclusive.

  SELECT artigo, preco FROM artigos WHERE preco >2 or preco<=3;

f) Mostrar apenas o nome do artigo e o preço dos artigos com preço inferior a 2 ou
superior a 4.

      SELECT artigo, preco FROM artigos WHERE preco<2 or preco >4;

g) Mostrar apenas o nome do artigo e o preço dos artigos com preço igual a 5 ou 2,5.

   SELECT artigo, preco FROM artigos WHEREpreco =5 or preco =2.5;

h) Mostrar os artigos cujo nome começa pela letra “M”.

  SELECT * FROM Artigos WHERE Artigo LIKE ‘M%’;

i) Mostrar os artigos que têm no nome a palavra “ate”.

 SELECT * FROM Artigos WHERE Artigo LIKE ‘%ate%’;

j) Mostrar os artigos cujo código começa por “A0”.

 SELECT * FROM Artigos WHERE Codigo LIKE ‘A0%’;

k) Mostrar todos os artigos ordenados por preço na ordem descendente.

  SELECT * FROM Artigos ODER BY Preco DESC;

l) Mostrar todos os artigos ordenados por preço na ordem ascendente.

 SELECT * FROM Artigos ORDER BY Preco ASC;

                                              4
m) Ordenar por ordem alfabética crescente os artigos com preço inferior a 3.



n) Contar o total de artigos.

   SELECT COUNT (Artigo) FROM Artigos;

o) Contar os artigos cujo preço é maior ou igual a 5.

   SELECT COUNT (Artigo) FROM Artigos WHERE Preco>=5;

p) Contar o número de fornecedores distintos através da tabela artigos.

   SELECT COUNT (Fornecedores) FROM Artigos;

q) Somar o preço de todos os artigos.

  SELECT SUM (Preco) FROM Artigos;

r) Calcular a média de preço de todos os artigos.

  SELECT AVG (Preco) FROM Artigos;

s) Calcular a média de preço de todos os artigos com preço inferior a 5.

  SELECT AVG (Artigo) FROM Artigos WHERE Preco>5;

t) Mostrar o artigo com o preço mais elevado.

  SELECT Artigo, MAX (Preco) FROM Artigos;

u) Mostrar o artigo com o preço mais baixo.

  SELECT Artigo, MIN (Preco) FROM Artigos;

v) Mostrar o artigo com o preço mais baixo proveniente do fornecedor “F101”.

  SELECT Artigo, MIN (Preco) FROM Artigos WHERE CodFornecedor LIKE F101;




                                              5

Weitere ähnliche Inhalte

Empfohlen

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Empfohlen (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Ficha 4 resolução

  • 1. Resolução da Ficha nº4 1. Abra o xamp 2. Cria uma base de dados (nome: Drogaria), com as seguintes tabelas: CREATE DATABASE Drogaria; Criar Tabelas : CREATE TABLE Fornecedores( CodFornecedor int(10); Nome varchar (30), Morada varchar (18), Telefone int (9), NrContribuinte int (10)); CREATE TABLE Artigos (CodArtigo int (10), Artigo varchar(10), preco varchar(10), CodFornecedor int (10)); CREATE TABLE Clientes( CodigoCliente int (10), Nome varchar (10), Morada varchar (10), Telefone int (10), NrContribuinte int (10)); 1
  • 2. CREATE TABLE Encomendas( NrEncomendas int(10), Data int(10), CodCliente int(10), CodArtigo int(10), Quantidade int (10)); 3. De seguida preencha a tabela com os seguintes dados: Inserir dados: INSERT INTO Artigos ( CodArtigo, Artigo, Preco, CodFornecedor) VALUES( A01, Alicate X, 2,15€, F101); Nota * : Para inserir o resto dos dados é sempre igual Inserir dados: INSERT INTO Clientes ( CodigoCliente, Nome, Morada, Telefone, NrContribuinte) VALUES (C111, Antunes, Aveiro, 234456456,235234534) Nota * : Para inserir o resto dos dados é sempre igual 2
  • 3. Inserir dados: INSERT INTO Fornecedore (CodFornecedor,Nome,Morada,Telefone,NrContribuinte) VALUES(F101,Coimbrox,Coimbre,234456456,234567890); Nota * : Para inserir o resto dos dados é sempre igual Inserir dados: INSERT INTO Encomendas ( NrEncomenda, Data, CodCliente, CodArtigo, Quantidade) VALUES (1, 02-12-2005, C111,A01,10); Nota * : Para inserir o resto dos dados é sempre igual 3
  • 4. a) Mostrar todos os registos da tabela Artigos. SELECT * FROM Artigos; b) Mostrar apenas o nome do artigo e o preço de todos os artigos. SELECT Nome, Preco FROM Artigos; c) Mostrar os artigos que têm preço inferior a 3. SELECT * FROM Artigos WHERE Preco<3; d) Mostrar apenas o nome do artigo e o preço dos artigos com preço menor que 3. SELECT Nome, Preco FROM Artigos WHERE Preco<3; e) Mostrar apenas o nome do artigo e o preço dos artigos com preço entre 2 e 3 inclusive. SELECT artigo, preco FROM artigos WHERE preco >2 or preco<=3; f) Mostrar apenas o nome do artigo e o preço dos artigos com preço inferior a 2 ou superior a 4. SELECT artigo, preco FROM artigos WHERE preco<2 or preco >4; g) Mostrar apenas o nome do artigo e o preço dos artigos com preço igual a 5 ou 2,5. SELECT artigo, preco FROM artigos WHEREpreco =5 or preco =2.5; h) Mostrar os artigos cujo nome começa pela letra “M”. SELECT * FROM Artigos WHERE Artigo LIKE ‘M%’; i) Mostrar os artigos que têm no nome a palavra “ate”. SELECT * FROM Artigos WHERE Artigo LIKE ‘%ate%’; j) Mostrar os artigos cujo código começa por “A0”. SELECT * FROM Artigos WHERE Codigo LIKE ‘A0%’; k) Mostrar todos os artigos ordenados por preço na ordem descendente. SELECT * FROM Artigos ODER BY Preco DESC; l) Mostrar todos os artigos ordenados por preço na ordem ascendente. SELECT * FROM Artigos ORDER BY Preco ASC; 4
  • 5. m) Ordenar por ordem alfabética crescente os artigos com preço inferior a 3. n) Contar o total de artigos. SELECT COUNT (Artigo) FROM Artigos; o) Contar os artigos cujo preço é maior ou igual a 5. SELECT COUNT (Artigo) FROM Artigos WHERE Preco>=5; p) Contar o número de fornecedores distintos através da tabela artigos. SELECT COUNT (Fornecedores) FROM Artigos; q) Somar o preço de todos os artigos. SELECT SUM (Preco) FROM Artigos; r) Calcular a média de preço de todos os artigos. SELECT AVG (Preco) FROM Artigos; s) Calcular a média de preço de todos os artigos com preço inferior a 5. SELECT AVG (Artigo) FROM Artigos WHERE Preco>5; t) Mostrar o artigo com o preço mais elevado. SELECT Artigo, MAX (Preco) FROM Artigos; u) Mostrar o artigo com o preço mais baixo. SELECT Artigo, MIN (Preco) FROM Artigos; v) Mostrar o artigo com o preço mais baixo proveniente do fornecedor “F101”. SELECT Artigo, MIN (Preco) FROM Artigos WHERE CodFornecedor LIKE F101; 5