¡Esta es una revisión vieja del documento!


SELECT V.SERIE, COL.NOMBRE,V.KM FROM VEHICULOS V INNER JOIN COLORES COL ON (COL.ID = V.COL_ID) INNER JOIN MARCAS M ON (M.ID = V.MAR_ID) WHERE M.NOMBRE='MAZDA' AND V.PRECIO BETWEEN 25000000::MONEY AND 30000000::MONEY AND V.MODELO=2008;

serie  | nombre |  km   

———+——–+——- 7765654 | AZUL | 65000

bd1214⇒ SELECT V.SERIE,V.PLACA,CIU.NOMBRE,KM,COL.NOMBRE,M.NOMBRE,PRECIO FROM VEHICULOS V LEFT JOIN CIUDADES CIU ON (CIU.ID = V.CIU_PLACA_ID) INNER JOIN COLORES COL ON (COL.ID = V.COL_ID) INNER JOIN MARCAS M ON (M.ID = V.MAR_ID);

 serie    | placa  |  nombre  |  km   | nombre |  nombre   |     precio     

————+——–+———-+——-+——–+———–+—————- 3435436673 | FGT485 | BOGOTA | 56000 | ROJO | MAZDA | $34,000,000.00 3435663233 | | | 0 | AZUL | RENAULT | $45,000,000.00 22234234 | BFT346 | BOGOTA | 43200 | NEGRO | MAZDA | $19,000,000.00 22367543 | POA211 | MEDELLIN | 23000 | BLANCO | MAZDA | $44,000,000.00 22245444 | | | 0 | BLANCO | CHEVROLET | $56,000,000.00 7887677676 | VVB322 | BOGOTA | 15000 | AZUL | RENAULT | $32,000,000.00 4454536773 | | | 0 | NEGRO | MAZDA | $78,000,000.00 3456776546 | AAQ111 | CALI | 98000 | BLANCO | RENAULT | $15,000,000.00 7765654 | KLK232 | MEDELLIN | 65000 | AZUL | MAZDA | $25,000,000.00 3345677 | MTR221 | BOGOTA | 34000 | NEGRO | CHEVROLET | $28,000,000.00

bd1214⇒ SELECT COUNT(*) FROM VEHICULOS WHERE PLACA IS NULL; count


   3

bd1214⇒ SELECT M.NOMBRE, COUNT(*) FROM VEHICULOS V INNER JOIN MARCAS M ON (M.ID = V.MAR_ID) bd1214→ GROUP BY M.NOMBRE bd1214→ HAVING COUNT(*) >2; nombre | count ———+——- RENAULT | 3 MAZDA | 5

SELECT DISTINCT COL.NOMBRE FROM VEHICULOS V INNER JOIN COLORES COL ON (COL.ID = V.COL_ID) INNER JOIN MARCAS M ON (M.ID = V.MAR_ID) WHERE M.NOMBRE='CHEVROLET';

nombre


BLANCO NEGRO

SELECT M.NOMBRE, COUNT(*) FROM VEHICULOS V INNER JOIN MARCAS M ON (M.ID = V.MAR_ID) GROUP BY M.NOMBRE HAVING COUNT(*) >= ALL (SELECT COUNT(*) FROM VEHICULOS V INNER JOIN MARCAS M ON (M.ID = V.MAR_ID) GROUP BY M.NOMBRE); nombre | count ——–+——- MAZDA | 5

SELECT NOMBRE FROM MARCAS WHERE ID NOT IN (SELECT MAR_ID FROM VEHICULOS WHERE PLACA IS NULL); nombre


(0 filas)

 
materias/respuestas-taller-sql.1332948192.txt.gz · Última modificación: 2012/03/28 10:23 por caolarte
Recent changes RSS feed Donate Powered by PHP Valid XHTML 1.0 Valid CSS Driven by DokuWiki