Advertisement
Guest User

TETETETETE

a guest
Jun 3rd, 2015
296
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.50 KB | None | 0 0
  1. 3.
  2.  
  3. mysql> select nombre, year(contrato) from Empleados;
  4. +-------------------+----------------+
  5. | nombre | year(contrato) |
  6. +-------------------+----------------+
  7. | Antonio Gutierrez | 1989 |
  8. | Paloma Blanco | 1992 |
  9. | Antonio Pazos | 1986 |
  10. | Ana Garcia | 1995 |
  11. | Amparo Beltran | 1998 |
  12. | Enrique Gomez | 2000 |
  13. | Nieves Soler | 1996 |
  14. | Juan Jose Velasco | 1997 |
  15. | Isidro Perez | 2000 |
  16. | Ignacio Lopez | 1990 |
  17. | Vicente Salvador | 1995 |
  18. | Carmen Hernandez | 1990 |
  19. | Juan Pons | 1994 |
  20. | Pedro Fernandez | 1999 |
  21. | Silvia Blasco | 1992 |
  22. | Jose Alegre | 1997 |
  23. | Cristina Prats | 1984 |
  24. | Carlos Gimenez | 1995 |
  25. | Maria Gonzalez | 1996 |
  26. | Manuel Torres | 1998 |
  27. | Jose Perez | 1996 |
  28. | Alejandro Martos | 1994 |
  29. | Veronica Muelas | 1997 |
  30. | Elena Lopez | 1994 |
  31. | Isabel Fernandez | 2000 |
  32. | Jose Mujica | 1987 |
  33. | Pedro Bledos | 1998 |
  34. | Pablo Costas | 1995 |
  35. | Ester Castro | 1996 |
  36. | Gregorio Mas | 1997 |
  37. | Jose Medina | 1995 |
  38. | Maria Utrillas | 1997 |
  39. | Marina Gilabert | 1998 |
  40. +-------------------+----------------+
  41. 33 rows in set (0.04 sec)
  42.  
  43. 4.
  44.  
  45. mysql> select edad from Empleados;
  46. +------+
  47. | edad |
  48. +------+
  49. | 45 |
  50. | 56 |
  51. | 52 |
  52. | 27 |
  53. | 28 |
  54. | 36 |
  55. | 25 |
  56. | 34 |
  57. | 22 |
  58. | 38 |
  59. | 29 |
  60. | 44 |
  61. | 50 |
  62. | 23 |
  63. | 33 |
  64. | 26 |
  65. | 46 |
  66. | 35 |
  67. | 37 |
  68. | 24 |
  69. | 28 |
  70. | 34 |
  71. | 25 |
  72. | 29 |
  73. | 22 |
  74. | 49 |
  75. | 26 |
  76. | 35 |
  77. | 27 |
  78. | 33 |
  79. | 34 |
  80. | 27 |
  81. | 24 |
  82. +------+
  83. 33 rows in set (0.00 sec)
  84.  
  85. 5.
  86.  
  87. mysql> select edad, count(edad) from Empleados group by edad;
  88. +------+-------------+
  89. | edad | count(edad) |
  90. +------+-------------+
  91. | 22 | 2 |
  92. | 23 | 1 |
  93. | 24 | 2 |
  94. | 25 | 2 |
  95. | 26 | 2 |
  96. | 27 | 3 |
  97. | 28 | 2 |
  98. | 29 | 2 |
  99. | 33 | 2 |
  100. | 34 | 3 |
  101. | 35 | 2 |
  102. | 36 | 1 |
  103. | 37 | 1 |
  104. | 38 | 1 |
  105. | 44 | 1 |
  106. | 45 | 1 |
  107. | 46 | 1 |
  108. | 49 | 1 |
  109. | 50 | 1 |
  110. | 52 | 1 |
  111. | 56 | 1 |
  112. +------+-------------+
  113. 21 rows in set (0.01 sec)
  114.  
  115. 6.
  116.  
  117. mysql> select departamento, avg(edad) from Empleados group by departamento;
  118. +--------------+-----------+
  119. | departamento | avg(edad) |
  120. +--------------+-----------+
  121. | 100 | 51.0000 |
  122. | 101 | 30.3333 |
  123. | 102 | 37.5000 |
  124. | 103 | 37.5000 |
  125. | 104 | 28.3333 |
  126. | 105 | 29.5000 |
  127. | 106 | 35.6667 |
  128. | 107 | 35.0000 |
  129. | 108 | 30.5000 |
  130. | 109 | 29.6667 |
  131. | 110 | 29.0000 |
  132. | 111 | 30.0000 |
  133. | 112 | 25.5000 |
  134. +--------------+-----------+
  135. 13 rows in set (0.00 sec)
  136.  
  137. 7.
  138.  
  139. mysql> select categoria from Categorias where salario > 35000;
  140. +-----------+
  141. | categoria |
  142. +-----------+
  143. | 1 |
  144. | 2 |
  145. +-----------+
  146. 2 rows in set (0.00 sec)
  147.  
  148. 8.
  149.  
  150. mysql> select * from Empleados where num=1014;
  151. +------+---------------+------+--------------+-----------+---------------------+
  152. | NUM | NOMBRE | EDAD | DEPARTAMENTO | CATEGORIA | CONTRATO |
  153. +------+---------------+------+--------------+-----------+---------------------+
  154. | 1014 | Silvia Blasco | 33 | 102 | 4 | 1992-02-23 00:00:00 |
  155. +------+---------------+------+--------------+-----------+---------------------+
  156. 1 row in set (0.00 sec)
  157.  
  158. 9.
  159.  
  160. mysql> select * from Empleados where departamento = 106;
  161. +------+----------------+------+--------------+-----------+---------------------+
  162. | NUM | NOMBRE | EDAD | DEPARTAMENTO | CATEGORIA | CONTRATO |
  163. +------+----------------+------+--------------+-----------+---------------------+
  164. | 1015 | Jose Alegre | 26 | 106 | 2 | 1997-08-26 00:00:00 |
  165. | 1016 | Cristina Prats | 46 | 106 | 4 | 1984-11-18 00:00:00 |
  166. | 1017 | Carlos Gimenez | 35 | 106 | 4 | 1995-05-15 00:00:00 |
  167. +------+----------------+------+--------------+-----------+---------------------+
  168. 3 rows in set (0.00 sec)
  169.  
  170. 10.
  171.  
  172. mysql> select nombre from Empleados where year(contrato) = 2000;
  173. +------------------+
  174. | nombre |
  175. +------------------+
  176. | Enrique Gomez |
  177. | Isidro Perez |
  178. | Isabel Fernandez |
  179. +------------------+
  180. 3 rows in set (0.00 sec)
  181.  
  182. 11.
  183.  
  184. mysql> select * from Empleados where categoria <> 4;
  185. +------+-------------------+------+--------------+-----------+---------------------+
  186. | NUM | NOMBRE | EDAD | DEPARTAMENTO | CATEGORIA | CONTRATO |
  187. +------+-------------------+------+--------------+-----------+---------------------+
  188. | 1000 | Antonio Gutierrez | 45 | 100 | 1 | 1989-01-12 00:00:00 |
  189. | 1001 | Paloma Blanco | 56 | 100 | 2 | 1992-03-17 00:00:00 |
  190. | 1002 | Antonio Pazos | 52 | 100 | 3 | 1986-03-14 00:00:00 |
  191. | 1003 | Ana Garcia | 27 | 101 | 2 | 1995-10-23 00:00:00 |
  192. | 1004 | Amparo Beltran | 28 | 101 | 3 | 1998-02-04 00:00:00 |
  193. | 1005 | Enrique Gomez | 36 | 101 | 3 | 2000-07-05 00:00:00 |
  194. | 1006 | Nieves Soler | 25 | 105 | 2 | 1996-03-13 00:00:00 |
  195. | 1007 | Juan Jose Velasco | 34 | 105 | 3 | 1997-02-14 00:00:00 |
  196. | 1008 | Isidro Perez | 22 | 109 | 2 | 2000-05-06 00:00:00 |
  197. | 1009 | Ignacio Lopez | 38 | 109 | 3 | 1990-04-07 00:00:00 |
  198. | 1010 | Vicente Salvador | 29 | 109 | 3 | 1995-07-08 00:00:00 |
  199. | 1011 | Carmen Hernandez | 44 | 102 | 2 | 1990-07-16 00:00:00 |
  200. | 1015 | Jose Alegre | 26 | 106 | 2 | 1997-08-26 00:00:00 |
  201. | 1020 | Jose Perez | 28 | 110 | 2 | 1996-03-22 00:00:00 |
  202. | 1025 | Jose Mujica | 49 | 103 | 2 | 1987-09-04 00:00:00 |
  203. | 1026 | Pedro Bledos | 26 | 103 | 5 | 1998-02-06 00:00:00 |
  204. | 1027 | Pablo Costas | 35 | 107 | 5 | 1995-07-03 00:00:00 |
  205. | 1028 | Ester Castro | 27 | 111 | 2 | 1996-07-18 00:00:00 |
  206. | 1029 | Gregorio Mas | 33 | 111 | 5 | 1997-03-14 00:00:00 |
  207. | 1030 | Jose Medina | 34 | 104 | 2 | 1995-06-14 00:00:00 |
  208. | 1031 | Maria Utrillas | 27 | 104 | 3 | 1997-08-19 00:00:00 |
  209. | 1032 | Marina Gilabert | 24 | 104 | 3 | 1998-12-01 00:00:00 |
  210. +------+-------------------+------+--------------+-----------+---------------------+
  211. 22 rows in set (0.00 sec)
  212.  
  213. 12.
  214.  
  215. mysql> select nombre from Empleados where year(contrato) between 1990 and 1994;
  216. +------------------+
  217. | nombre |
  218. +------------------+
  219. | Paloma Blanco |
  220. | Ignacio Lopez |
  221. | Carmen Hernandez |
  222. | Juan Pons |
  223. | Silvia Blasco |
  224. | Alejandro Martos |
  225. | Elena Lopez |
  226. +------------------+
  227. 7 rows in set (0.00 sec)
  228.  
  229. 13.
  230.  
  231. mysql> select categoria from Categorias where salario < '35000' or salario > '40000';
  232. +-----------+
  233. | categoria |
  234. +-----------+
  235. | 1 |
  236. | 5 |
  237. +-----------+
  238. 2 rows in set (0.00 sec)
  239.  
  240. 14.
  241.  
  242. mysql> select nombre from Empleados where categoria IN (1,2);
  243. # También es válido
  244. # mysql> select nombre from Empleados where categoria = 1 OR categoria = 2;
  245. +-------------------+
  246. | nombre |
  247. +-------------------+
  248. | Antonio Gutierrez |
  249. | Paloma Blanco |
  250. | Ana Garcia |
  251. | Nieves Soler |
  252. | Isidro Perez |
  253. | Carmen Hernandez |
  254. | Jose Alegre |
  255. | Jose Perez |
  256. | Jose Mujica |
  257. | Ester Castro |
  258. | Jose Medina |
  259. +-------------------+
  260. 11 rows in set (0.00 sec)
  261.  
  262. 15.
  263.  
  264. mysql> select nombre from Empleados where nombre like 'Jose %';
  265. +-------------+
  266. | nombre |
  267. +-------------+
  268. | Jose Alegre |
  269. | Jose Perez |
  270. | Jose Mujica |
  271. | Jose Medina |
  272. +-------------+
  273. 4 rows in set (0.00 sec)
  274.  
  275. 16.
  276.  
  277. mysql> select nombre from Empleados where categoria = '3' and edad > '35';
  278. +---------------+
  279. | nombre |
  280. +---------------+
  281. | Antonio Pazos |
  282. | Enrique Gomez |
  283. | Ignacio Lopez |
  284. +---------------+
  285. 3 rows in set (0.00 sec)
  286.  
  287. 17.
  288.  
  289. mysql> select nombre from Empleados where not departamento = 110;
  290. +-------------------+
  291. | nombre |
  292. +-------------------+
  293. | Antonio Gutierrez |
  294. | Paloma Blanco |
  295. | Antonio Pazos |
  296. | Ana Garcia |
  297. | Amparo Beltran |
  298. | Enrique Gomez |
  299. | Nieves Soler |
  300. | Juan Jose Velasco |
  301. | Isidro Perez |
  302. | Ignacio Lopez |
  303. | Vicente Salvador |
  304. | Carmen Hernandez |
  305. | Juan Pons |
  306. | Pedro Fernandez |
  307. | Silvia Blasco |
  308. | Jose Alegre |
  309. | Cristina Prats |
  310. | Carlos Gimenez |
  311. | Maria Gonzalez |
  312. | Manuel Torres |
  313. | Elena Lopez |
  314. | Isabel Fernandez |
  315. | Jose Mujica |
  316. | Pedro Bledos |
  317. | Pablo Costas |
  318. | Ester Castro |
  319. | Gregorio Mas |
  320. | Jose Medina |
  321. | Maria Utrillas |
  322. | Marina Gilabert |
  323. +-------------------+
  324. 30 rows in set (0.00 sec)
  325.  
  326. 18.
  327.  
  328. mysql> select nombre, edad from Empleados order by edad;
  329. +-------------------+------+
  330. | nombre | edad |
  331. +-------------------+------+
  332. | Isabel Fernandez | 22 |
  333. | Isidro Perez | 22 |
  334. | Pedro Fernandez | 23 |
  335. | Manuel Torres | 24 |
  336. | Marina Gilabert | 24 |
  337. | Nieves Soler | 25 |
  338. | Veronica Muelas | 25 |
  339. | Pedro Bledos | 26 |
  340. | Jose Alegre | 26 |
  341. | Maria Utrillas | 27 |
  342. | Ester Castro | 27 |
  343. | Ana Garcia | 27 |
  344. | Amparo Beltran | 28 |
  345. | Jose Perez | 28 |
  346. | Vicente Salvador | 29 |
  347. | Elena Lopez | 29 |
  348. | Gregorio Mas | 33 |
  349. | Silvia Blasco | 33 |
  350. | Juan Jose Velasco | 34 |
  351. | Alejandro Martos | 34 |
  352. | Jose Medina | 34 |
  353. | Carlos Gimenez | 35 |
  354. | Pablo Costas | 35 |
  355. | Enrique Gomez | 36 |
  356. | Maria Gonzalez | 37 |
  357. | Ignacio Lopez | 38 |
  358. | Carmen Hernandez | 44 |
  359. | Antonio Gutierrez | 45 |
  360. | Cristina Prats | 46 |
  361. | Jose Mujica | 49 |
  362. | Juan Pons | 50 |
  363. | Antonio Pazos | 52 |
  364. | Paloma Blanco | 56 |
  365. +-------------------+------+
  366. 33 rows in set (0.00 sec)
  367.  
  368. 19.
  369.  
  370. mysql> select nombre, edad from Empleados order by nombre desc;
  371. +-------------------+------+
  372. | nombre | edad |
  373. +-------------------+------+
  374. | Vicente Salvador | 29 |
  375. | Veronica Muelas | 25 |
  376. | Silvia Blasco | 33 |
  377. | Pedro Fernandez | 23 |
  378. | Pedro Bledos | 26 |
  379. | Paloma Blanco | 56 |
  380. | Pablo Costas | 35 |
  381. | Nieves Soler | 25 |
  382. | Marina Gilabert | 24 |
  383. | Maria Utrillas | 27 |
  384. | Maria Gonzalez | 37 |
  385. | Manuel Torres | 24 |
  386. | Juan Pons | 50 |
  387. | Juan Jose Velasco | 34 |
  388. | Jose Perez | 28 |
  389. | Jose Mujica | 49 |
  390. | Jose Medina | 34 |
  391. | Jose Alegre | 26 |
  392. | Isidro Perez | 22 |
  393. | Isabel Fernandez | 22 |
  394. | Ignacio Lopez | 38 |
  395. | Gregorio Mas | 33 |
  396. | Ester Castro | 27 |
  397. | Enrique Gomez | 36 |
  398. | Elena Lopez | 29 |
  399. | Cristina Prats | 46 |
  400. | Carmen Hernandez | 44 |
  401. | Carlos Gimenez | 35 |
  402. | Antonio Pazos | 52 |
  403. | Antonio Gutierrez | 45 |
  404. | Ana Garcia | 27 |
  405. | Amparo Beltran | 28 |
  406. | Alejandro Martos | 34 |
  407. +-------------------+------+
  408. 33 rows in set (0.00 sec)
  409.  
  410. 20.
  411.  
  412. [...]
  413.  
  414. 21.
  415.  
  416. mysql> select codigo, telefono from Dptoficinas, Oficinas where Dptoficinas.oficina = Oficinas.oficina and region = 'Centro';
  417. +--------+-----------+
  418. | codigo | telefono |
  419. +--------+-----------+
  420. | 109 | 913641000 |
  421. | 110 | 913641100 |
  422. | 111 | 913641200 |
  423. | 112 | 925871000 |
  424. +--------+-----------+
  425. 4 rows in set (0.02 sec)
  426.  
  427. 22.
  428.  
  429. mysql> select nombre, ciudad from Empleados, Oficinas, Dptoficinas where Empleados.departamento = codigo and Dptoficinas.oficina = Oficinas.oficina;
  430. +-------------------+-----------+
  431. | nombre | ciudad |
  432. +-------------------+-----------+
  433. | Antonio Gutierrez | Valencia |
  434. | Paloma Blanco | Valencia |
  435. | Antonio Pazos | Valencia |
  436. | Ana Garcia | Valencia |
  437. | Amparo Beltran | Valencia |
  438. | Enrique Gomez | Valencia |
  439. | Carmen Hernandez | Valencia |
  440. | Juan Pons | Valencia |
  441. | Pedro Fernandez | Valencia |
  442. | Silvia Blasco | Valencia |
  443. | Jose Mujica | Valencia |
  444. | Pedro Bledos | Valencia |
  445. | Jose Medina | Valencia |
  446. | Maria Utrillas | Valencia |
  447. | Marina Gilabert | Valencia |
  448. | Nieves Soler | Barcelona |
  449. | Juan Jose Velasco | Barcelona |
  450. | Jose Alegre | Barcelona |
  451. | Cristina Prats | Barcelona |
  452. | Carlos Gimenez | Barcelona |
  453. | Pablo Costas | Barcelona |
  454. | Maria Gonzalez | Alicante |
  455. | Manuel Torres | Alicante |
  456. | Isidro Perez | Madrid |
  457. | Ignacio Lopez | Madrid |
  458. | Vicente Salvador | Madrid |
  459. | Jose Perez | Madrid |
  460. | Alejandro Martos | Madrid |
  461. | Veronica Muelas | Madrid |
  462. | Ester Castro | Madrid |
  463. | Gregorio Mas | Madrid |
  464. | Elena Lopez | Toledo |
  465. | Isabel Fernandez | Toledo |
  466. +-------------------+-----------+
  467. 33 rows in set (0.00 sec)
  468.  
  469. 23.
  470.  
  471. mysql> select sum(salario) from Categorias, Empleados where Empleados.categoria = Categorias.categoria;
  472. +--------------+
  473. | sum(salario) |
  474. +--------------+
  475. | 1190000 |
  476. +--------------+
  477. 1 row in set (0.00 sec)
  478.  
  479. 24.
  480.  
  481. mysql> select avg(salario) from Empleados, Categorias, Dptoficinas, Oficinas where Empleados.categoria = Categorias.categoria and Empleados.departamento = codigo and Dptoficinas.oficina = Oficinas.oficina and ciudad = 'Barcelona';
  482. +--------------+
  483. | avg(salario) |
  484. +--------------+
  485. | 35000.0000 |
  486. +--------------+
  487. 1 row in set (0.00 sec)
  488.  
  489. 25.
  490.  
  491. mysql> select max(salario), min(salario) from Empleados, Categorias where Empleados.categoria = Categorias.categoria;
  492. +--------------+--------------+
  493. | max(salario) | min(salario) |
  494. +--------------+--------------+
  495. | 50000 | 25000 |
  496. +--------------+--------------+
  497. 1 row in set (0.00 sec)
  498.  
  499. 26.
  500.  
  501. mysql> select count(*) from Empleados where edad > 40;
  502. +----------+
  503. | count(*) |
  504. +----------+
  505. | 7 |
  506. +----------+
  507. 1 row in set (0.00 sec)
  508.  
  509. 27.
  510.  
  511. mysql> select count(distinct edad) from Empleados;
  512. +----------------------+
  513. | count(distinct edad) |
  514. +----------------------+
  515. | 21 |
  516. +----------------------+
  517. 1 row in set (0.00 sec)
  518.  
  519. 28.
  520.  
  521. mysql> select ciudad, sum(salario) from Empleados, Categorias, Dptoficinas, Oficinas where Empleados.categoria = Categorias.categoria and Empleados.departamento = codigo and Dptoficinas.oficina = Oficinas.oficina group by Oficinas.oficina, ciudad;
  522. +-----------+--------------+
  523. | ciudad | sum(salario) |
  524. +-----------+--------------+
  525. | Valencia | 555000 |
  526. | Barcelona | 210000 |
  527. | Alicante | 70000 |
  528. | Madrid | 285000 |
  529. | Toledo | 70000 |
  530. +-----------+--------------+
  531. 5 rows in set (0.03 sec)
  532.  
  533. 29.
  534.  
  535. [...]
  536.  
  537. 30.
  538.  
  539. [...]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement