PRÁCTICAS DE BASES DE DATOS I - Universidad de Jaén
PRÁCTICAS DE BASES DE DATOS I - Universidad de Jaén
PRÁCTICAS DE BASES DE DATOS I - Universidad de Jaén
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
Programación <strong>de</strong> Bases <strong>de</strong> Datos Oracle SQL<br />
J9999AB 10.6<br />
M3020KY 5.5<br />
Este comando <strong>de</strong>vuelve para cada coche, su matrícula y la suma <strong>de</strong> horas trabajadas en dicho<br />
coche. Los trabajos se agrupan por matrícula y a cada grupo se le calcula la suma <strong>de</strong>l atributo horas.<br />
Finalmente se <strong>de</strong>vuelve una tupla por grupo, conteniendo la información <strong>de</strong> la matrícula y la suma <strong>de</strong><br />
horas trabajadas.<br />
En la siguiente tabla se muestra el proceso <strong>de</strong> generación <strong>de</strong>l resultado anterior. En esta tabla se<br />
muestran las matrículas y las horas <strong>de</strong> cada trabajo or<strong>de</strong>nadas por matrícula. El proceso consiste por<br />
tanto en juntar las horas <strong>de</strong> los trabajos <strong>de</strong> igual matrícula (GROUP BY mat) y sumar sus horas,<br />
<strong>de</strong>volviendo la matrícula y la suma calculada.<br />
MAT HORAS<br />
-------- ---------<br />
B4444AC 3.2 SUM(horas) = 3.2<br />
CA0000AD 8 SUM(horas) = 8<br />
GR1111AK 5.5<br />
GR1111AK 2.5 SUM(horas) = 8<br />
GR4321A 2.1 SUM(horas) = 2.1<br />
J1234Z 2.2<br />
J1234Z 3<br />
J1234Z 7 SUM(horas) = 12.2<br />
J9999AB 1<br />
J9999AB 7.7<br />
J9999AB .7<br />
J9999AB 1.2 SUM(horas) = 10.6<br />
M3020KY 1<br />
M3020KY 2.5<br />
M3020KY 2 SUM(horas) = 5.5<br />
• Consultar el número <strong>de</strong> trabajos realizados a cada coche:<br />
SQL> SELECT mat,COUNT(*)<br />
FROM trabajos<br />
GROUP by mat<br />
OR<strong>DE</strong>R by mat;<br />
MAT COUNT(*)<br />
-------- ---------<br />
B4444AC 1<br />
CA0000AD 1<br />
GR1111AK 2<br />
GR4321A 1<br />
J1234Z 3<br />
J9999AB 4<br />
M3020KY 3<br />
• Consultar el número medio <strong>de</strong> horas trabajadas por puesto clasificados por tipo <strong>de</strong> contrato<br />
( atributo parcial):<br />
SQL> SELECT parcial,puesto,AVG(horas)<br />
FROM trabajos,mecanicos<br />
<strong>Universidad</strong> <strong>de</strong> <strong>Jaén</strong> 28