tomasfdel

TBD Práctica 3

Oct 14th, 2018
339
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 3.50 KB | None | 0 0
  1. 1  - SELECT * FROM J;
  2. 2  - SELECT * FROM S WHERE CIUDAD = "Londres";
  3. 3  - SELECT DISTINCT S# FROM SPJ WHERE J# = "J1" ORDER BY S#;
  4. 4  - SELECT * FROM SPJ WHERE CANT >= 300 AND CANT <= 750;
  5. 5  - SELECT DISTINCT COLOR, CIUDAD FROM P;
  6.  
  7. 6  - SELECT S#, P#, J# FROM S,P,J WHERE S.CIUDAD = P.CIUDAD AND P.CIUDAD = J.CIUDAD;
  8. 7  - SELECT S#, P#, J# FROM S,P,J WHERE S.CIUDAD <> P.CIUDAD OR S.CIUDAD <> J.CIUDAD;
  9. 8  - SELECT S#, P#, J# FROM S,P,J WHERE S.CIUDAD <> P.CIUDAD AND S.CIUDAD <> J.CIUDAD AND P.CIUDAD <> J.CIUDAD;
  10. 9  - SELECT DISTINCT P# FROM SPJ,S WHERE SPJ.S# = S.S# AND S.CIUDAD = "Londres";
  11. 10 - SELECT DISTINCT P# FROM SPJ, S, J WHERE SPJ.S# = S.S# AND SPJ.J# = J.J# AND S.CIUDAD = "Londres" AND J.CIUDAD = "Londres";
  12. 11 - SELECT DISTINCT S.CIUDAD, J.CIUDAD FROM SPJ, S, J WHERE SPJ.S# = S.S# AND SPJ.J# = J.J#;
  13. 12 - SELECT DISTINCT P# FROM SPJ, S, J WHERE SPJ.S# = S.S# AND SPJ.J# = J.J# AND S.CIUDAD = J.CIUDAD;
  14. 13 - SELECT DISTINCT J# FROM SPJ, S, J WHERE SPJ.S# = S.S# AND SPJ.J# = J.J# AND S.CIUDAD <> J.CIUDAD;
  15. 14 - SELECT DISTINCT T1.P# T2.P# FROM SPJ T1, SPJ T2 WHERE T1.S# = T2.S# AND T1.P# <> T2.P#;
  16.  
  17. 15 - SELECT COUNT(DISTINCT J#) FROM SPJ WHERE S# = "S1";
  18. 16 - SELECT SUM(CANT) FROM SPJ WHERE S# = "S1" AND P# = "P1";
  19. 17 - SELECT P#, J#, SUM(CANT) FROM SPJ GROUP BY P#, J#;
  20. 18 - SELECT P# FROM SPJ GROUP BY P# HAVING AVG(CANT) > 320;
  21.  
  22. 19 - SELECT * FROM SPJ WHERE CANT IS NOT NULL;
  23. 20 - SELECT J#, CIUDAD FROM J WHERE CIUDAD LIKE "_o%";
  24.  
  25. 21 - SELECT JNOMBRE FROM J WHERE J# IN (SELECT DISTINCT J# FROM SPJ WHERE S# = "S1");
  26. 22 - SELECT COLOR FROM P WHERE P# IN (SELECT DISTINCT P# FROM SPJ WHERE S# = "S1");
  27. 23 - (Se podría resolver directamente con la subconsulta)
  28.      SELECT P# FROM P WHERE P# IN (SELECT DISTINCT P# FROM SPJ, J WHERE SPJ.J# = J.J# AND J.CIUDAD = "Londres");
  29. 24 - SELECT DISTINCT J# FROM SPJ WHERE P# IN (SELECT DISTINCT P# FROM SPJ WHERE S# = "S1");
  30. 25 - SELECT DISTINCT S# FROM SPJ WHERE P# IN
  31.         (SELECT DISTINCT P# FROM SPJ WHERE S# IN
  32.             (SELECT DISTINCT S# FROM SPJ, P WHERE SPJ.P# = P.P# AND P.COLOR = "Rojo"));
  33. 26 - SELECT S# FROM S WHERE SITUACION < (SELECT SITUACION FROM S WHERE S# = "S1");
  34. 27 - SELECT J# FROM J WHERE CIUDAD = (SELECT MIN(CIUDAD) FROM J);
  35.  
  36. 28 - SELECT P# FROM P WHERE EXISTS
  37.          (SELECT * FROM J WHERE J.CIUDAD = "Londres" AND EXISTS
  38.               (SELECT * FROM SPJ WHERE SPJ.J# = J.J# AND SPJ.P# = P.P#));
  39. 29 - SELECT J# FROM J WHERE EXISTS
  40.          (SELECT * FROM SPJ WHERE SPJ.J# = J.J# AND EXISTS
  41.              (SELECT P# FROM P WHERE SPJ.P# = P.P# EXISTS
  42.                   (SELECT * FROM SPJ SPJ2 WHERE SPJ2.P# = P# AND SPJ2.S# = "S1");
  43. 30 - SELECT J# FROM J WHERE NOT EXISTS
  44.          (SELECT * FROM P WHERE P.COLOR = "Rojo" AND EXISTS
  45.               (SELECT * FROM S WHERE S.CIUDAD = "Londres" AND EXISTS
  46.                   (SELECT * FROM SPJ WHERE SPJ.S# = S.S# AND SPJ.R# = R.R# AND SPJ.J# = J.J#)));
  47. 31 - SELECT J# FROM J WHERE NOT EXISTS
  48.          (SELECT * FROM S WHERE S# <> "S1" AND EXISTS
  49.              (SELECT * FROM SPJ WHERE SPJ.S# = S.S# AND SPJ.J# = J.J#))
  50.      AND EXISTS (SELECT * FROM SPJ WHERE S# = "S1" AND SPJ.J# = J.J#);
  51.  
  52. 32 - SELECT DISTINCT CIUDAD FROM
  53.      ((SELECT DISTINCT CIUDAD FROM S) UNION
  54.       (SELECT DISTINCT CIUDAD FROM P) UNION
  55.       (SELECT DISTINCT CIUDAD FROM J))
  56.      ORDER BY CIUDAD;
  57.  
  58. 33 - UPDATE P SET COLOR = "Gris" WHERE COLOR = "Rojo";
  59. 34 - DELETE FROM J WHERE J# NOT IN (SELECT DISTINCT J# FROM SPJ);
  60. 35 - INSERT INTO S (S#, NOMBRE, CIUDAD) VALUES ("S10", "Salazar", "Nueva York");
Add Comment
Please, Sign In to add comment