0% found this document useful (0 votes)
482 views6 pages

Respuestas Ejercicios Netcraker

The document provides 9 examples of SQL queries to retrieve, update, and delete data from various database tables. The queries select products by manufacturer, update columns, delete rows, find the most expensive product for each maker, count devices by manufacturer and type, order devices by price, and determine which is cheaper between PCs and laptops based on specifications.

Uploaded by

JOSE LUIS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
482 views6 pages

Respuestas Ejercicios Netcraker

The document provides 9 examples of SQL queries to retrieve, update, and delete data from various database tables. The queries select products by manufacturer, update columns, delete rows, find the most expensive product for each maker, count devices by manufacturer and type, order devices by price, and determine which is cheaper between PCs and laptops based on specifications.

Uploaded by

JOSE LUIS
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 6

Jose Luis Jimenez De la Luz

Solución de Ejercicios de SQL


1. Create query to update column transferred_to to ‘Invalid_destination’ in Storage table if
transferred_to column is equal 100.

update storage
set transfered_to = 'invalid_destination'
where transfered_to = '100’

2.- Create query to select all products of Dell manufacturer.

select * from product


where maker = 'Dell';

3.- Create query to delete rows from Storage table that have value ‘Invalid_destination’ in
transferred_to column.

DELETE FROM Storage


where transfered_to = 'invalid_destination'
4. Create query to select most expensive product for every maker. Output should have maker,
product model and price.

select a.model Modelo,


a.price Precio,
b.maker Fabricante
from printer a , product b
where a.model = b.model
and a.price = ( SELECT MAX( price ) FROM printer )

select a.model Modelo,


a.price Precio,
b.maker Fabricante
from laptop a , product b
where a.model = b.model
and a.price = ( SELECT MAX( price ) FROM laptop )

select a.model Modelo,


a.price Precio,
b.maker Fabricante
from pc a , product b
where a.model = b.model
and a.price = ( SELECT MAX( price ) FROM pc )

5. Create query to select overall amount of laptops that Hitachi manufactures.


select count(maker) Total_Laptops from product
where maker = 'Hitachi'
and type = 'laptop'

6. Create query to select all devices ordered from most expensive ones to cheapest. Output should
have serial number, maker, price, type.

select a.serial_number Numero_Serie,


d.maker Marca,
a.price Precio,
d.type Tipo
from printer a,
product d
where d.model = a.model
union all
select a.serial_number Numero_Serie,
d.maker Marca,
a.price Precio,
d.type Tipo
from pc a,
product d
where d.model = a.model
union all
select a.serial_number Numero_Serie,
d.maker Marca,
a.price Precio,
d.type Tipo
from laptop a,
product d
where d.model = a.model
order by Precio desc
7. Create query to select makers that make more printers than pc\laptops.

SELECT maker Marca


FROM product
GROUP BY maker
HAVING SUM(CASE WHEN type = 'PC' THEN 1 ELSE 0 END) > 0
AND SUM(CASE WHEN type = 'Laptop' THEN 1 ELSE 0 END) = 0
AND SUM(CASE WHEN type = 'Printer' THEN 1 ELSE 0 END) = 0

8. Create query to select most expensive PC without CD drive for makers who manufacture only
PCs. Output should have serial_number, maker, price.

select b.serial_number Numero_Serie,


a.maker Marca,
b.price Precio
from product a,
pc b
where a.model = b. model
and b.cd is null
and b.price = ( SELECT MAX( price ) FROM pc )

9. Create query to select what's cheaper pc or laptop (considering speed, ram, hd). If maker
doesn't manufacture pc then laptop should be shown as cheapest and vice versa.
As input you have speed, ram, hd. as output you should show at least maker, serial_number, speed, ram,
hd, price.

SELECT DISTINCT(p.maker) Marca,


pc.serial_number,
pc.speed,
pc.ram,
pc.hd,
pc.price Precio
FROM product p
INNER JOIN pc
ON pc.MODEL = p.MODEL
WHERE pc.speed =
( SELECT MAX(speed) speed FROM pc WHERE ram =
(SELECT Max(ram) FROM pc
)
)
AND pc.hd = (SELECT MIN(hd) FROM pc)
ORDER BY pc.price asc;
UNION
SELECT DISTINCT(p.maker) Marca,
lap.serial_number,
lap.speed,
lap.ram,
lap.hd,
lap.price Precio
FROM product p
INNER JOIN laptop lap
ON lap.MODEL = p.MODEL
WHERE lap.speed =
( SELECT MAX(speed) speed FROM pc WHERE ram =
(SELECT Max(ram) FROM pc
)
)
AND lap.hd = (SELECT MIN(hd) FROM pc)
ORDER BY lap.price asc;

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy