Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 1. Datos de los productos de la marca "Samsung" y de la marca "Apple"
- ordenados de caro a barato.
- +------------+-----------+-----------------------------------------------------------------------------------+---------+
- | Referencia | Categoria | Descripción | Precio |
- +------------+-----------+-----------------------------------------------------------------------------------+---------+
- | Mac-001 | 3 | Apple iMac Retina pantaila 5k 27'', Core i5, 8Gb RAM memoria, 1Tb Disko gogorrean | 2099.00 |
- | Led-003 | 7 | Samsung 55'' HG55ec690ebxxc LED FullHD/SmartTV/HDMI/VGA/USB/Wifi | 1350.98 |
- | Lap-003 | 3 | Apple MacBok Pro MB990LL/A 13.3 Inch Laptop Hard Disk 160Gb, 2Gb DDR3 RAM memoria | 419.00 |
- | SwA-001 | 5 | Apple SmartWatch Leader Edition | 399.00 |
- | SGa-001 | 4 | Samsung Galaxy Ace Pro Design | 249.00 |
- | Fab-002 | 6 | Fablet Apple 128Gb | 244.00 |
- | Sam-001 | 6 | Samsung 64Gb 12'' tablet ultraeramangarria, 2Gb RAM | 235.00 |
- | Fab-001 | 6 | Fablet Samsung 64Gb | 175.00 |
- | Pan-002 | 3 | Samsung 25'' LED Full Definition beltza | 98.00 |
- | Ffu-002 | 2 | Apple fablet funda babesgarria | 35.00 |
- | Fun-001 | 4 | iPhone funda babesgarria | 34.00 |
- | AGa-001 | 4 | Samsung Funda babesgarria | 8.00 |
- | CSa-001 | 4 | Samsung Mugikor kargadorea | 6.00 |
- +------------+-----------+-----------------------------------------------------------------------------------+---------+
- 13 rows in set (0.00 sec)
- SELECT Ref AS Referencia, Categoria, Descripcion AS Descripción, Precio
- FROM Producto
- WHERE Marca = "Samsung" OR Marca = "Apple"
- ORDER BY Precio DESC;
- 2. Número de unidades vendidas por producto.
- +----------+------------------+
- | Producto | UnidadesVendidas |
- +----------+------------------+
- | Fal-001 | 6 |
- | SwA-001 | 10 |
- | Tos-001 | 12 |
- | Tos-002 | 3 |
- | WOS-002 | 50 |
- +----------+------------------+
- 5 rows in set (0.03 sec)
- SELECT Producto, SUM(Unidades) AS UnidadesVendidas
- FROM Venta
- GROUP BY Producto;
- 3. Precio del producto más caro de aquellos cuya referencia comienza por 'Tos'.
- +--------+
- | Precio |
- +--------+
- | 84.95 |
- +--------+
- SELECT Precio
- FROM Producto
- WHERE Ref LIKE 'Tos%'
- HAVING MAX(Precio);
- 4. Lista de productos con la referencia separada en dos columnas y una tercera
- que incluya 20 caracteres de la descripción más el precio entre corchetes.
- +--------+---------+--------------------------------+
- | Letras | Numeros | Descripcion [Precio] |
- +--------+---------+--------------------------------+
- | AGa | 001 | Samsung Funda babesg [8.00] |
- | Asu | 001 | Asus Z97-K SK1150 DD [184.00] |
- | Bat | 001 | Bateria Li-ion 4000m [33.00] |
- | Civ | 004 | Sid Meier's Civiliza [29.95] |
- | Civ | 005 | Sid Meier's Civiliza [49.95] |
- | CSa | 001 | Samsung Mugikor karg [6.00] |
- | ··· | ··· | ··· |
- 72 rows in set
- SELECT SUBSTR(Ref,1,3) AS Letras,SUBSTR(Ref,5,3) AS Numeros,
- CONCAT(SUBSTR(Descripcion,1,20)," [",Precio,"]") AS 'Descripcion [Precio]'
- FROM Producto;
- 5. Información completa sobre las ventas.
- +----------+------------+----------+--------------+--------+----------+-----------+---------+
- | CodVenta | Fecha | Producto | Nombre | Precio | Unidades | Marca | Importe |
- +----------+------------+----------+--------------+--------+----------+-----------+---------+
- | 1 | 2016-09-01 | WOS-002 | Smartphone | 293.70 | 3 | Microsoft | 881.10 |
- | 2 | 2016-09-01 | Tos-002 | PC-Portátil | 57.95 | 1 | Toshiba | 57.95 |
- | 3 | 2016-09-02 | Tos-002 | PC-Portátil | 57.95 | 2 | Toshiba | 115.90 |
- | 4 | 2016-10-01 | WOS-002 | Smartphone | 293.70 | 3 | Microsoft | 881.10 |
- | 5 | 2016-10-01 | Fal-001 | Complemento | 34.00 | 3 | NetWay | 102.00 |
- | 6 | 2016-10-01 | WOS-002 | Smartphone | 293.70 | 3 | Microsoft | 881.10 |
- | ··· | ··· | ··· | ··· | ··· | ··· | ··· | ··· |
- 28 rows in set (0.00 sec)
- SELECT CodVenta,Fecha,Producto,Nombre,Precio,Unidades,Marca,Precio*Unidades AS Importe
- FROM Venta
- INNER JOIN Producto ON Ref = Producto
- INNER JOIN Categoria ON IdCategoria = Categoria;
- 6. Categorías de las que tenemos más de 5 productos.
- +-----------+--------------+
- | Categoria | NumProductos |
- +-----------+--------------+
- | 1 | 14 |
- | 2 | 16 |
- | 3 | 19 |
- | 4 | 12 |
- | 7 | 6 |
- +-----------+--------------+
- 5 rows in set (0.00 sec)
- SELECT Categoria,COUNT(ref) AS NumProductos FROM Producto
- GROUP BY Categoria
- HAVING NumProductos > "5";
- 7. Lista de productos ordenada por unidades vendidas. Deben aparecer también
- los productos no vendidos.
- +---------+------------------+
- | Ref | UnidadesVendidas |
- +---------+------------------+
- | WOS-002 | 50 |
- | Tos-001 | 12 |
- | SwA-001 | 10 |
- | Fal-001 | 6 |
- | Tos-002 | 3 |
- | AGa-001 | NULL |
- | Fox-001 | NULL |
- | Led-003 | NULL |
- | ··· | ··· |
- 72 rows in set (0.00 sec)
- SELECT Ref,SUM(Unidades) AS UnidadesVendidas
- FROM Producto
- LEFT JOIN Venta ON Ref = Producto
- GROUP BY Ref
- ORDER BY UnidadesVendidas DESC;
- 8. Lista de productos no vendidos. Si la marca es NULL deberemos mostrar el
- texto "Clónico".
- +---------------+---------+---------+-----------+
- | Marca | Ref | Precio | Categoria |
- +---------------+---------+---------+-----------+
- | Apple | Fab-002 | 244.00 | 6 |
- | Apple | Ffu-002 | 35.00 | 2 |
- | Apple | Fun-001 | 34.00 | 4 |
- | Apple | Lap-003 | 419.00 | 3 |
- | Apple | Mac-001 | 2099.00 | 3 |
- | Asus | Asu-001 | 184.00 | 2 |
- | B-Move | Fal-003 | 67.00 | 2 |
- | B-Move | Ffu-001 | 23.00 | 2 |
- | BestTextil | Fal-002 | 45.00 | 2 |
- | BestTextil | Fun-002 | 15.00 | 4 |
- | BestTextil | Mal-001 | 59.00 | 2 |
- | BlueSens | Tdt-001 | 129.00 | 7 |
- | Clónico | Bat-001 | 33.00 | 2 |
- | ··· | ··· | ··· | ··· |
- 67 rows in set
- SELECT IF(Marca IS NULL,"Clonico",Marca) AS Marca,Ref,Precio,Categoria
- FROM Producto
- LEFT JOIN Venta ON Ref = Producto
- WHERE Unidades IS NULL
- GROUP BY Ref
- ORDER BY Marca;
- 9. Productos de la marca “Apple” que son más baratos que el “Samsung” más
- caro de la categoria 4.
- +---------+---------+-----------+--------+-----------+--------------------------------+-------+
- | Ref | Fabref | Categoria | Precio | Capacidad | Descripcion | Marca |
- +---------+---------+-----------+--------+-----------+--------------------------------+-------+
- | Fab-002 | fght543 | 6 | 244.00 | 128Gb | Fablet Apple 128Gb | Apple |
- | Ffu-002 | 234ge | 2 | 35.00 | NULL | Apple fablet funda babesgarria | Apple |
- | Fun-001 | g23t5 | 4 | 34.00 | NULL | iPhone funda babesgarria | Apple |
- +---------+---------+-----------+--------+-----------+--------------------------------+-------+
- SELECT * FROM Producto
- WHERE Marca = "Apple" AND
- Precio < (SELECT MAX(precio) FROM Producto
- WHERE Marca = "Samsung" AND Categoria = "4");
- 10. Importe total facturado cada mes.
- +------+------+--------------+
- | Año | Mes | ImporteTotal |
- +------+------+--------------+
- | 2016 | 9 | 1054.95 |
- | 2016 | 10 | 1966.20 |
- | 2016 | 11 | 1762.20 |
- | 2016 | 12 | 5037.30 |
- | 2017 | 1 | 4992.90 |
- | 2017 | 2 | 1596.00 |
- | 2017 | 3 | 84.95 |
- | 2017 | 4 | 254.85 |
- | 2017 | 9 | 679.60 |
- | 2017 | 10 | 2643.30 |
- +------+------+--------------+
- 10 rows in set (0.00 sec)
- SELECT YEAR(Fecha) AS Año, MONTH(Fecha) AS Mes, SUM(Precio*Unidades) AS ImporteTotal
- FROM Venta
- INNER JOIN Producto ON Ref = Producto
- GROUP BY Año,Mes;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement