SlideShare una empresa de Scribd logo
1 de 42
Julián Araneda
Gonzalo Berger
Antonio Lena
Sebastián Urrutia
Gastón Martini
Sistemas de Bases de Datos II
Base de Datos
La base de datos sobre la que trabajamos
está constituida por partes, proveedores y
proyectos, los cuáles a su vez se
encuentran relacionados, formando una
cuarta tabla de envíos.
Tablas
Las tablas resultantes son:
• S (proveedores).
• P (partes).
• J (proyectos).
• SPJ (envíos).
Proveedores
La tabla de proveedores está constituida
por los siguientes atributos:
sid: Identificador del proveedor.
snombre: Nombre del proveedor.
situacion: Situación del proveedor.
ciudad: Ciudad del proveedor.
Partes
La tabla de partes está constituida por los
siguientes atributos:
pid: Identificador de la parte.
pnombre: Nombre de la parte.
color: Color de la parte.
peso: Peso de la parte.
ciudad: Ciudad de la parte.
Proyectos
La tabla de proyectos está constituida por
los siguientes atributos:
jid: Identificador del proyecto.
jnombre: Nombre del proyecto.
ciudad: Ciudad del proyecto.
Manipulación DML
A continuación, veremos algunos ejemplos
de consultas simples hechas con SELECT.
La sintaxis del SELECT es:
select [distinct] elemento(s) from tabla(s)
[where condición]
[group by campo(s)]
[having condición]
[order by campo(s)]
Consulta Nº 1
 Obtener el numero y la situación de
todos los proveedores de París
 Select sid, situacion from s where
ciudad=“París”;
Consulta Nº 2
 Obtener los números de partes de todas
las partes suministrados.
 Select distinct p.pid as P1 from s,p;
Consulta Nº 3
 Obtener los datos completos de todos
los proveedores:
 Select * from s;
Consulta Nº 4
 Obtener los números de los
proveedores radicados en parís cuya
situación sea mayor que 20:
 Select sid from s where ciudad=“París”
and situacion > 20;
Consulta Nº 5
 Obtener los números de proveedor y
situación de los proveedores radicados
en parís en orden descendiente por
situación.
 Select sid, situacion from s where
ciudad=“París” order by situacion desc;
Consulta Nº 6
 Obtener todas las combinación de
información de proveedores y partes
tales que el proveedor y la parte en
cuestión este situados en la misma
ciudad.
 Select * from s,p where s.ciudad =
p.ciudad;
Consulta Nº 6
Consulta Nº 6
Consulta Nº 6
Consulta Nº 7
 Obtener todas las combinaciones de
información de proveedor y parte donde
la ciudad que el proveedor siga a la
cuidad de la parte en orden alfabético.
 Select * from s,p where s.ciudad >
p.ciudad;
Consulta Nº 7
Consulta Nº 7
Consulta Nº 8
 Obtener todas las combinaciones de
información de proveedor y parte donde
el proveedor y la parte en cuestión
estén cosituados, pero omitiendo a los
proveedores cuya situación sea 20.
 Select * from s,p where s.ciudad =
p.ciudad and s.situacion <> 20;
Consulta Nº 8
Consulta Nº 8
Consulta Nº 9
 Obtener todas las combinaciones de
numero de proveedor/numero de parte
tales que el proveedor y la parte en
cuestión estén cosituados.
 Select sid, pid from s,p where s.ciudad =
p.ciudad;
Consulta Nº 9
Consulta Nº 10
 Obtener todas las parejas de nombres
de ciudad tales que un proveedor
situado en la primera ciudad suministre
una parte almacenada en la segunda
ciudad.
 Select distinct s.ciudad, p.ciudad from s,
spj, p where s.sid = spj.sid and spj.pid =
p.pid;
Consulta Nº 10
Consulta Nº 11
 Obtener todas las parejas de las bases
de datos de numero de proveedor tales
que los dos proveedores estén
cosituados.
 Select primera.sid, segunda.sid from s
primera, s segunda where
primera.ciudad = segunda.sid;
Consulta Nº 11
Funciones agregadas
 Count (atributo clave) – Numero de valores
en la columna.
 Count (*) – Numero de valores en la
columna, los valores nulos se manejan
igual a los no nulos.
 Sum (atributo clave numérico) - Suma de
los valores de la columna.
 Avg (Atributo clave numérico) – Promedio
de los valores de la columna.
 Max () – Valor mas grande en la columna.
 Min () – Valor mas pequeño en la columna.
Consulta 1
 Obtener el numero de proveedores
 Select count (*) from s;
Consulta 2
 Obtener el numero total de proveedores
que suministran partes en la actualidad.
 Select count (distinct sid) from spj;
Consulta 3
 Obtener el numero de envíos de la parte
P2.
 Select count (*) from spj where pid=‘P2’;
Consulta 4
 Obtener la cantidad total suministrada
de la parte P2
 Select sum(cantidad) from spj where
pid=‘P2’
Consulta 5
 Obtener para cada parte suministrada el
numero de parte y la cantidad enviada
de esa parte.
 Select pid, sum(cantidad) from spj group
by pid;
Consulta 6
 Obtener los números de todas las
partes suministradas por mas de un
proveedor.
 Select pid from spj group by pid having
count(*) > 1;
Consulta 7
 Obtener todas las partes cuyos nombres
comiencen con “B”.
 Select * from p where pnombre like
‘B%’;
Consulta 9
 Obtener todos los nombres de los
proveedores que suministran la parte
P2.
 Select snombre from s where sid in
(select sid from spj where pid = ‘P2’)
Consulta 10
 Obtener todos los nombres de los
proveedores que suministran la parte P2
 Select snombre from s,spj where s.sid =
spj.sid and spj.pid=‘P2’
Consulta 11
 Obtener los nombres de los
proveedores que suministran por lo
menos una parte roja.
 Select distinct s.snombre from s, p, spj
where s.sid=spj.sid and p.pid=spj.pid
and p.color=‘Rojo’
Consulta 12
 Obtener los números de proveedores
situados en la misma ciudad que el
proveedor “S1”.
 Select sid from s where ciudad = (select
ciudad from s where sid=‘S1’)
Consulta 13
 Obtener los números de proveedores
cuya situación sea menor que el valor
máximo actual de la situación en la tabla
s.
 Select sid from s where situacion <
(select max (situacion) from s)
Consulta 14
 Obtener los nombres de proveedores
que suministran la parte P2.
 Select snombre from s where exists
(select * from spj where spj.sid = s.sid
and pid=‘P2’)

Más contenido relacionado

Destacado

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
 

Destacado (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...
 

Manipulacion de datos y funciones agregadas informix

  • 1. Julián Araneda Gonzalo Berger Antonio Lena Sebastián Urrutia Gastón Martini Sistemas de Bases de Datos II
  • 2. Base de Datos La base de datos sobre la que trabajamos está constituida por partes, proveedores y proyectos, los cuáles a su vez se encuentran relacionados, formando una cuarta tabla de envíos.
  • 3. Tablas Las tablas resultantes son: • S (proveedores). • P (partes). • J (proyectos). • SPJ (envíos).
  • 4. Proveedores La tabla de proveedores está constituida por los siguientes atributos: sid: Identificador del proveedor. snombre: Nombre del proveedor. situacion: Situación del proveedor. ciudad: Ciudad del proveedor.
  • 5. Partes La tabla de partes está constituida por los siguientes atributos: pid: Identificador de la parte. pnombre: Nombre de la parte. color: Color de la parte. peso: Peso de la parte. ciudad: Ciudad de la parte.
  • 6. Proyectos La tabla de proyectos está constituida por los siguientes atributos: jid: Identificador del proyecto. jnombre: Nombre del proyecto. ciudad: Ciudad del proyecto.
  • 7. Manipulación DML A continuación, veremos algunos ejemplos de consultas simples hechas con SELECT. La sintaxis del SELECT es: select [distinct] elemento(s) from tabla(s) [where condición] [group by campo(s)] [having condición] [order by campo(s)]
  • 8. Consulta Nº 1  Obtener el numero y la situación de todos los proveedores de París  Select sid, situacion from s where ciudad=“París”;
  • 9. Consulta Nº 2  Obtener los números de partes de todas las partes suministrados.  Select distinct p.pid as P1 from s,p;
  • 10. Consulta Nº 3  Obtener los datos completos de todos los proveedores:  Select * from s;
  • 11. Consulta Nº 4  Obtener los números de los proveedores radicados en parís cuya situación sea mayor que 20:  Select sid from s where ciudad=“París” and situacion > 20;
  • 12. Consulta Nº 5  Obtener los números de proveedor y situación de los proveedores radicados en parís en orden descendiente por situación.  Select sid, situacion from s where ciudad=“París” order by situacion desc;
  • 13. Consulta Nº 6  Obtener todas las combinación de información de proveedores y partes tales que el proveedor y la parte en cuestión este situados en la misma ciudad.  Select * from s,p where s.ciudad = p.ciudad;
  • 17. Consulta Nº 7  Obtener todas las combinaciones de información de proveedor y parte donde la ciudad que el proveedor siga a la cuidad de la parte en orden alfabético.  Select * from s,p where s.ciudad > p.ciudad;
  • 20. Consulta Nº 8  Obtener todas las combinaciones de información de proveedor y parte donde el proveedor y la parte en cuestión estén cosituados, pero omitiendo a los proveedores cuya situación sea 20.  Select * from s,p where s.ciudad = p.ciudad and s.situacion <> 20;
  • 23. Consulta Nº 9  Obtener todas las combinaciones de numero de proveedor/numero de parte tales que el proveedor y la parte en cuestión estén cosituados.  Select sid, pid from s,p where s.ciudad = p.ciudad;
  • 25. Consulta Nº 10  Obtener todas las parejas de nombres de ciudad tales que un proveedor situado en la primera ciudad suministre una parte almacenada en la segunda ciudad.  Select distinct s.ciudad, p.ciudad from s, spj, p where s.sid = spj.sid and spj.pid = p.pid;
  • 27. Consulta Nº 11  Obtener todas las parejas de las bases de datos de numero de proveedor tales que los dos proveedores estén cosituados.  Select primera.sid, segunda.sid from s primera, s segunda where primera.ciudad = segunda.sid;
  • 29. Funciones agregadas  Count (atributo clave) – Numero de valores en la columna.  Count (*) – Numero de valores en la columna, los valores nulos se manejan igual a los no nulos.  Sum (atributo clave numérico) - Suma de los valores de la columna.  Avg (Atributo clave numérico) – Promedio de los valores de la columna.  Max () – Valor mas grande en la columna.  Min () – Valor mas pequeño en la columna.
  • 30. Consulta 1  Obtener el numero de proveedores  Select count (*) from s;
  • 31. Consulta 2  Obtener el numero total de proveedores que suministran partes en la actualidad.  Select count (distinct sid) from spj;
  • 32. Consulta 3  Obtener el numero de envíos de la parte P2.  Select count (*) from spj where pid=‘P2’;
  • 33. Consulta 4  Obtener la cantidad total suministrada de la parte P2  Select sum(cantidad) from spj where pid=‘P2’
  • 34. Consulta 5  Obtener para cada parte suministrada el numero de parte y la cantidad enviada de esa parte.  Select pid, sum(cantidad) from spj group by pid;
  • 35. Consulta 6  Obtener los números de todas las partes suministradas por mas de un proveedor.  Select pid from spj group by pid having count(*) > 1;
  • 36. Consulta 7  Obtener todas las partes cuyos nombres comiencen con “B”.  Select * from p where pnombre like ‘B%’;
  • 37. Consulta 9  Obtener todos los nombres de los proveedores que suministran la parte P2.  Select snombre from s where sid in (select sid from spj where pid = ‘P2’)
  • 38. Consulta 10  Obtener todos los nombres de los proveedores que suministran la parte P2  Select snombre from s,spj where s.sid = spj.sid and spj.pid=‘P2’
  • 39. Consulta 11  Obtener los nombres de los proveedores que suministran por lo menos una parte roja.  Select distinct s.snombre from s, p, spj where s.sid=spj.sid and p.pid=spj.pid and p.color=‘Rojo’
  • 40. Consulta 12  Obtener los números de proveedores situados en la misma ciudad que el proveedor “S1”.  Select sid from s where ciudad = (select ciudad from s where sid=‘S1’)
  • 41. Consulta 13  Obtener los números de proveedores cuya situación sea menor que el valor máximo actual de la situación en la tabla s.  Select sid from s where situacion < (select max (situacion) from s)
  • 42. Consulta 14  Obtener los nombres de proveedores que suministran la parte P2.  Select snombre from s where exists (select * from spj where spj.sid = s.sid and pid=‘P2’)