Advertisement
Guest User

Untitled

a guest
Feb 21st, 2018
292
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 7.20 KB | None | 0 0
  1. 1. Datos de los productos de la marca "Samsung" y de la marca "Apple"
  2. ordenados de caro a barato.
  3. +------------+-----------+-----------------------------------------------------------------------------------+---------+
  4. | Referencia | Categoria | Descripción | Precio |
  5. +------------+-----------+-----------------------------------------------------------------------------------+---------+
  6. | Mac-001 | 3 | Apple iMac Retina pantaila 5k 27'', Core i5, 8Gb RAM memoria, 1Tb Disko gogorrean | 2099.00 |
  7. | Led-003 | 7 | Samsung 55'' HG55ec690ebxxc LED FullHD/SmartTV/HDMI/VGA/USB/Wifi | 1350.98 |
  8. | Lap-003 | 3 | Apple MacBok Pro MB990LL/A 13.3 Inch Laptop Hard Disk 160Gb, 2Gb DDR3 RAM memoria | 419.00 |
  9. | SwA-001 | 5 | Apple SmartWatch Leader Edition | 399.00 |
  10. | SGa-001 | 4 | Samsung Galaxy Ace Pro Design | 249.00 |
  11. | Fab-002 | 6 | Fablet Apple 128Gb | 244.00 |
  12. | Sam-001 | 6 | Samsung 64Gb 12'' tablet ultraeramangarria, 2Gb RAM | 235.00 |
  13. | Fab-001 | 6 | Fablet Samsung 64Gb | 175.00 |
  14. | Pan-002 | 3 | Samsung 25'' LED Full Definition beltza | 98.00 |
  15. | Ffu-002 | 2 | Apple fablet funda babesgarria | 35.00 |
  16. | Fun-001 | 4 | iPhone funda babesgarria | 34.00 |
  17. | AGa-001 | 4 | Samsung Funda babesgarria | 8.00 |
  18. | CSa-001 | 4 | Samsung Mugikor kargadorea | 6.00 |
  19. +------------+-----------+-----------------------------------------------------------------------------------+---------+
  20. 13 rows in set (0.00 sec)
  21.  
  22. SELECT Ref AS Referencia, Categoria, Descripcion AS Descripción, Precio
  23. FROM Producto
  24. WHERE Marca = "Samsung" OR Marca = "Apple"
  25. ORDER BY Precio DESC;
  26.  
  27. 2. Número de unidades vendidas por producto.
  28. +----------+------------------+
  29. | Producto | UnidadesVendidas |
  30. +----------+------------------+
  31. | Fal-001 | 6 |
  32. | SwA-001 | 10 |
  33. | Tos-001 | 12 |
  34. | Tos-002 | 3 |
  35. | WOS-002 | 50 |
  36. +----------+------------------+
  37. 5 rows in set (0.03 sec)
  38.  
  39. SELECT Producto, SUM(Unidades) AS UnidadesVendidas
  40. FROM Venta
  41. GROUP BY Producto;
  42.  
  43. 3. Precio del producto más caro de aquellos cuya referencia comienza por 'Tos'.
  44. +--------+
  45. | Precio |
  46. +--------+
  47. | 84.95 |
  48. +--------+
  49.  
  50. SELECT Precio
  51. FROM Producto
  52. WHERE Ref LIKE 'Tos%'
  53. HAVING MAX(Precio);
  54.  
  55.  
  56. 4. Lista de productos con la referencia separada en dos columnas y una tercera
  57. que incluya 20 caracteres de la descripción más el precio entre corchetes.
  58. +--------+---------+--------------------------------+
  59. | Letras | Numeros | Descripcion [Precio] |
  60. +--------+---------+--------------------------------+
  61. | AGa | 001 | Samsung Funda babesg [8.00] |
  62. | Asu | 001 | Asus Z97-K SK1150 DD [184.00] |
  63. | Bat | 001 | Bateria Li-ion 4000m [33.00] |
  64. | Civ | 004 | Sid Meier's Civiliza [29.95] |
  65. | Civ | 005 | Sid Meier's Civiliza [49.95] |
  66. | CSa | 001 | Samsung Mugikor karg [6.00] |
  67. | ··· | ··· | ··· |
  68. 72 rows in set
  69.  
  70. SELECT SUBSTR(Ref,1,3) AS Letras,SUBSTR(Ref,5,3) AS Numeros,
  71. CONCAT(SUBSTR(Descripcion,1,20)," [",Precio,"]") AS 'Descripcion [Precio]'
  72. FROM Producto;
  73.  
  74. 5. Información completa sobre las ventas.
  75. +----------+------------+----------+--------------+--------+----------+-----------+---------+
  76. | CodVenta | Fecha | Producto | Nombre | Precio | Unidades | Marca | Importe |
  77. +----------+------------+----------+--------------+--------+----------+-----------+---------+
  78. | 1 | 2016-09-01 | WOS-002 | Smartphone | 293.70 | 3 | Microsoft | 881.10 |
  79. | 2 | 2016-09-01 | Tos-002 | PC-Portátil | 57.95 | 1 | Toshiba | 57.95 |
  80. | 3 | 2016-09-02 | Tos-002 | PC-Portátil | 57.95 | 2 | Toshiba | 115.90 |
  81. | 4 | 2016-10-01 | WOS-002 | Smartphone | 293.70 | 3 | Microsoft | 881.10 |
  82. | 5 | 2016-10-01 | Fal-001 | Complemento | 34.00 | 3 | NetWay | 102.00 |
  83. | 6 | 2016-10-01 | WOS-002 | Smartphone | 293.70 | 3 | Microsoft | 881.10 |
  84. | ··· | ··· | ··· | ··· | ··· | ··· | ··· | ··· |
  85. 28 rows in set (0.00 sec)
  86.  
  87. SELECT CodVenta,Fecha,Producto,Nombre,Precio,Unidades,Marca,Precio*Unidades AS Importe
  88. FROM Venta
  89. INNER JOIN Producto ON Ref = Producto
  90. INNER JOIN Categoria ON IdCategoria = Categoria;
  91.  
  92. 6. Categorías de las que tenemos más de 5 productos.
  93. +-----------+--------------+
  94. | Categoria | NumProductos |
  95. +-----------+--------------+
  96. | 1 | 14 |
  97. | 2 | 16 |
  98. | 3 | 19 |
  99. | 4 | 12 |
  100. | 7 | 6 |
  101. +-----------+--------------+
  102. 5 rows in set (0.00 sec)
  103.  
  104. SELECT Categoria,COUNT(ref) AS NumProductos FROM Producto
  105. GROUP BY Categoria
  106. HAVING NumProductos > "5";
  107.  
  108. 7. Lista de productos ordenada por unidades vendidas. Deben aparecer también
  109. los productos no vendidos.
  110. +---------+------------------+
  111. | Ref | UnidadesVendidas |
  112. +---------+------------------+
  113. | WOS-002 | 50 |
  114. | Tos-001 | 12 |
  115. | SwA-001 | 10 |
  116. | Fal-001 | 6 |
  117. | Tos-002 | 3 |
  118. | AGa-001 | NULL |
  119. | Fox-001 | NULL |
  120. | Led-003 | NULL |
  121. | ··· | ··· |
  122. 72 rows in set (0.00 sec)
  123.  
  124. SELECT Ref,SUM(Unidades) AS UnidadesVendidas
  125. FROM Producto
  126. LEFT JOIN Venta ON Ref = Producto
  127. GROUP BY Ref
  128. ORDER BY UnidadesVendidas DESC;
  129.  
  130. 8. Lista de productos no vendidos. Si la marca es NULL deberemos mostrar el
  131. texto "Clónico".
  132. +---------------+---------+---------+-----------+
  133. | Marca | Ref | Precio | Categoria |
  134. +---------------+---------+---------+-----------+
  135. | Apple | Fab-002 | 244.00 | 6 |
  136. | Apple | Ffu-002 | 35.00 | 2 |
  137. | Apple | Fun-001 | 34.00 | 4 |
  138. | Apple | Lap-003 | 419.00 | 3 |
  139. | Apple | Mac-001 | 2099.00 | 3 |
  140. | Asus | Asu-001 | 184.00 | 2 |
  141. | B-Move | Fal-003 | 67.00 | 2 |
  142. | B-Move | Ffu-001 | 23.00 | 2 |
  143. | BestTextil | Fal-002 | 45.00 | 2 |
  144. | BestTextil | Fun-002 | 15.00 | 4 |
  145. | BestTextil | Mal-001 | 59.00 | 2 |
  146. | BlueSens | Tdt-001 | 129.00 | 7 |
  147. | Clónico | Bat-001 | 33.00 | 2 |
  148. | ··· | ··· | ··· | ··· |
  149. 67 rows in set
  150.  
  151. SELECT IF(Marca IS NULL,"Clonico",Marca) AS Marca,Ref,Precio,Categoria
  152. FROM Producto
  153. LEFT JOIN Venta ON Ref = Producto
  154. WHERE Unidades IS NULL
  155. GROUP BY Ref
  156. ORDER BY Marca;
  157.  
  158. 9. Productos de la marca “Apple” que son más baratos que el “Samsung” más
  159. caro de la categoria 4.
  160. +---------+---------+-----------+--------+-----------+--------------------------------+-------+
  161. | Ref | Fabref | Categoria | Precio | Capacidad | Descripcion | Marca |
  162. +---------+---------+-----------+--------+-----------+--------------------------------+-------+
  163. | Fab-002 | fght543 | 6 | 244.00 | 128Gb | Fablet Apple 128Gb | Apple |
  164. | Ffu-002 | 234ge | 2 | 35.00 | NULL | Apple fablet funda babesgarria | Apple |
  165. | Fun-001 | g23t5 | 4 | 34.00 | NULL | iPhone funda babesgarria | Apple |
  166. +---------+---------+-----------+--------+-----------+--------------------------------+-------+
  167.  
  168. SELECT * FROM Producto
  169. WHERE Marca = "Apple" AND
  170. Precio < (SELECT MAX(precio) FROM Producto
  171. WHERE Marca = "Samsung" AND Categoria = "4");
  172.  
  173. 10. Importe total facturado cada mes.
  174. +------+------+--------------+
  175. | Año | Mes | ImporteTotal |
  176. +------+------+--------------+
  177. | 2016 | 9 | 1054.95 |
  178. | 2016 | 10 | 1966.20 |
  179. | 2016 | 11 | 1762.20 |
  180. | 2016 | 12 | 5037.30 |
  181. | 2017 | 1 | 4992.90 |
  182. | 2017 | 2 | 1596.00 |
  183. | 2017 | 3 | 84.95 |
  184. | 2017 | 4 | 254.85 |
  185. | 2017 | 9 | 679.60 |
  186. | 2017 | 10 | 2643.30 |
  187. +------+------+--------------+
  188. 10 rows in set (0.00 sec)
  189.  
  190. SELECT YEAR(Fecha) AS Año, MONTH(Fecha) AS Mes, SUM(Precio*Unidades) AS ImporteTotal
  191. FROM Venta
  192. INNER JOIN Producto ON Ref = Producto
  193. GROUP BY Año,Mes;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement