Anda di halaman 1dari 2

Consultas Modulo I

Emplee la BD Infracciones (entregada dentro del material del


proyecto) y desarrolle las siguientes preguntas:
1. Seleccione los nombres y apellidos de propietarios que tienen ms de un
vehculo
2. Seleccione todos los campos de aquellas papeletas que se han impuesto
en la segunda quincena del mes de Marzo del 2006
3. Seleccione las placas de vehculos, la descripcin de su color y marca,
as como su multa acumulada por todas las papeletas impuestas
4. Seleccione el cdigo y descripcin de las infracciones que no han
generado papeletas.
5. Seleccione las descripciones de marcas y la cantidad de vehculos por
cada marca.
SOLUCION:
1.
SELECT P.COD_PROPIETARIO, NOM_PROPIETARIO, APE_PROPIETARIO,
COUNT(NUM_PLACA) AS VEHICULOS
FROM TB_AUTO A INNER JOIN TB_PROPIETARIO P
ON A.COD_PROPIETARIO=P.COD_PROPIETARIO
GROUP BY P.COD_PROPIETARIO, NOM_PROPIETARIO, APE_PROPIETARIO
HAVING COUNT(NUM_PLACA)>=2
2.
SELECT NUM_PAPELETA, FEC_PAPELETA, COD_INFRACCION,
NUM_PLACA, EST_PAPELETA, COD_AGENTE
FROM TB_PAPELETA
WHERE YEAR(FEC_PAPELETA)=2006 AND MONTH(FEC_PAPELETA)=03
AND DAY(FEC_PAPELETA)>15
3.
SELECT NUM_PLACA, DES_MARCA, DES_COLOR
FROM (TB_COLOR INNER JOIN
(TB_AUTO INNER JOIN TB_MARCA ON TB_AUTO.COD_MARCA =
TB_MARCA.COD_MARCA)
ON TB_COLOR.COD_COLOR = TB_AUTO.COD_COLOR)
4.
SELECT I.COD_INFRACCION, DES_INFRACCION
FROM TB_INFRACCION I LEFT OUTER JOIN TB_PAPELETA P
ON I.COD_INFRACCION=P.COD_INFRACCION
WHERE NUM_PAPELETA IS NULL
5.
SELECT DES_MARCA, COUNT(A.COD_MARCA)
FROM TB_MARCA M INNER JOIN TB_AUTO A
ON M.COD_MARCA=A.COD_MARCA

GROUP BY DES_MARCA

Anda mungkin juga menyukai