Advertisement
AnAriyan

SQL Problem Solution 1 to 50

Nov 21st, 2017
2,577
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
SQL 16.89 KB | None | 0 0
  1. Site :  http://www.sql-ex.com
  2. res-  
  3. https://github.com/anyinlover/anyinlover.github.io/BLOB/master/_posts/2016-6-22-sql-exercise.md
  4.  
  5. 1. Find the model NUMBER, speed AND hard drive capacity FOR ALL the PCs WITH prices below $500.RESULT SET: model, speed, hd.
  6.  
  7.    ~~~SQL
  8.    SELECT model, speed, hd
  9.    FROM PC
  10.    WHERE price<500;
  11.    ~~~
  12.  
  13. 2. List ALL printer makers. RESULT SET: maker.
  14.  
  15.    ~~~SQL
  16.    SELECT DISTINCT maker
  17.    FROM Product
  18.    WHERE TYPE='Printer';
  19.    ~~~
  20.  
  21. 3. Find the model NUMBER, RAM AND screen SIZE OF the laptops WITH prices OVER $1000.
  22.  
  23.    ~~~SQL
  24.    SELECT model, ram, screen
  25.    FROM Laptop
  26.    WHERE price>1000;
  27.    ~~~
  28.  
  29. 4. Find ALL records FROM the Printer TABLE containing DATA about color printers.
  30.  
  31.    ~~~SQL
  32.    SELECT *
  33.    FROM Printer
  34.    WHERE color='y';
  35.    ~~~
  36.  
  37. 5. Find the model NUMBER, speed AND hard drive capacity OF PCs cheaper than $600 HAVING a 12x OR a 24x CD drive.
  38.  
  39.    ~~~SQL
  40.    SELECT model, speed, hd
  41.    FROM PC
  42.    WHERE price<600
  43.    AND cd IN ('12x','24x');
  44.    ~~~
  45.  
  46. 6. FOR each maker producing laptops WITH a hard drive capacity OF 10 Gb OR higher, find the speed OF such laptops. RESULT SET: maker, speed.
  47.  
  48.    ~~~SQL
  49.    SELECT DISTINCT maker, speed
  50.    FROM Product, Laptop
  51.    WHERE Product.model = Laptop.model
  52.    AND hd >= 10;
  53.    ~~~
  54.  
  55. 7. Find OUT the models AND prices FOR ALL the products (OF any TYPE) produced BY maker B.
  56.  
  57.    ~~~SQL
  58.    SELECT Product.model, price
  59.    FROM Product, PC
  60.    WHERE Product.model = PC.model
  61.    AND maker='B'
  62.    UNION
  63.    SELECT Product.model, price
  64.    FROM Product, Laptop
  65.    WHERE Product.model = Laptop.model
  66.    AND maker='B'
  67.    UNION
  68.    SELECT Product.model, price
  69.    FROM Product, Printer
  70.    WHERE Product.model = Printer.model
  71.    AND maker='B';
  72.    ~~~
  73.  
  74. 8. Find the makers producing PCs but NOT laptops.
  75.  
  76.    ~~~SQL
  77.    SELECT DISTINCT maker
  78.    FROM Product
  79.    WHERE TYPE='PC'
  80.    AND maker NOT IN
  81.    (SELECT DISTINCT maker
  82.    FROM Product
  83.    WHERE TYPE='Laptop')
  84.    ~~~
  85.  
  86. 9. Find the makers OF PCs WITH a processor speed OF 450 MHz OR more. RESULT SET: maker.
  87.  
  88.    ~~~SQL
  89.    SELECT DISTINCT maker
  90.    FROM Product, PC
  91.    WHERE Product.model = PC.model
  92.    AND speed >= 450;
  93.    ~~~
  94.  
  95. 10. Find the printer models HAVING the highest price. RESULT SET: model, price.
  96.  
  97.     ~~~SQL
  98.     SELECT model, price
  99.     FROM Printer
  100.     WHERE price =
  101.     (SELECT MAX(price)
  102.     FROM Printer);
  103.     ~~~
  104.  
  105. 11. Find OUT the average speed OF PCs.
  106.  
  107.     ~~~SQL
  108.     SELECT avg(speed)
  109.     FROM PC;
  110.     ~~~
  111.  
  112. 12. Find OUT the average speed OF the laptops priced OVER $1000.
  113.  
  114.     ~~~SQL
  115.     SELECT avg(speed)
  116.     FROM Laptop
  117.     WHERE price > 1000;
  118.     ~~~
  119.  
  120. 13. Find OUT the average speed OF the PCs produced BY maker A.
  121.  
  122.     ~~~SQL
  123.     SELECT avg(speed)
  124.     FROM Product, PC
  125.     WHERE Product.model = PC.model
  126.     AND maker='A';
  127.     ~~~
  128.  
  129. 14. GET the makers who produce ONLY one product TYPE AND more than one model. Output: maker, TYPE.
  130.  
  131.     ~~~SQL
  132.     SELECT DISTINCT maker, TYPE
  133.     FROM Product
  134.     WHERE maker IN
  135.     (SELECT maker
  136.     FROM Product
  137.     GROUP BY maker
  138.     HAVING COUNT(DISTINCT TYPE)=1
  139.     AND COUNT(DISTINCT model)>1);
  140.     ~~~
  141.  
  142. 15. GET hard drive capacities that are identical FOR two OR more PCs. RESULT SET: hd.
  143.  
  144.     ~~~SQL
  145.     SELECT hd
  146.     FROM PC
  147.     GROUP BY hd
  148.     HAVING COUNT(*) > 1
  149.     ~~~
  150.  
  151. 16. GET pairs OF PC models WITH identical speeds AND the same RAM capacity. Each resulting pair should be displayed ONLY once, i.e. (i, j) but NOT (j, i). RESULT SET: model WITH the bigger NUMBER, model WITH the smaller NUMBER, speed, AND RAM.
  152.  
  153.     ~~~SQL
  154.     SELECT DISTINCT p1.model, p2.model, p1.speed, p1.ram
  155.     FROM PC p1, PC p2
  156.     WHERE p1.model > p2.model
  157.     AND p1.speed = p2.speed
  158.     AND p1.ram = p2.ram;
  159.     ~~~
  160.  
  161. 17. GET the laptop models that have a speed smaller than the speed OF any PC. RESULT SET: TYPE, model, speed.
  162.  
  163.     ~~~SQL
  164.     SELECT DISTINCT TYPE, Product.model, speed
  165.     FROM Product, Laptop
  166.     WHERE Product.model = Laptop.model
  167.     AND speed <
  168.     (SELECT MIN(speed)
  169.     FROM PC);
  170.     ~~~
  171.  
  172. 18. Find the makers OF the cheapest color printers.RESULT SET: maker, price.
  173.  
  174.     ~~~SQL
  175.     SELECT DISTINCT maker, price
  176.     FROM Printer, Product
  177.     WHERE Product.model=Printer.model
  178.     AND color='y'
  179.     AND price=
  180.     (SELECT MIN(price)
  181.     FROM Printer
  182.     WHERE color='y');
  183.     ~~~
  184.  
  185. 19. FOR each maker HAVING models IN the Laptop TABLE, find OUT the average screen SIZE OF the laptops he produces. RESULT SET: maker, average screen SIZE.
  186.  
  187.     ~~~SQL
  188.     SELECT maker, avg(screen)
  189.     FROM Product, Laptop
  190.     WHERE Product.model = Laptop.model
  191.     GROUP BY maker;
  192.     ~~~
  193.  
  194. 20. Find the makers producing at least three DISTINCT models OF PCs. RESULT SET: maker, NUMBER OF PC models.
  195.  
  196.     ~~~SQL
  197.     SELECT maker, COUNT(model)
  198.     FROM Product
  199.     WHERE TYPE='PC'
  200.     GROUP BY maker
  201.     HAVING COUNT(model) >= 3;
  202.     ~~~
  203.  
  204. 21. Find OUT the maximum PC price FOR each maker HAVING models IN the PC TABLE. RESULT SET: maker, maximum price.
  205.  
  206.     ~~~SQL
  207.     SELECT maker, MAX(price)
  208.     FROM Product, PC
  209.     WHERE Product.model = PC.model
  210.     GROUP BY maker;
  211.     ~~~
  212.  
  213. 22. FOR each VALUE OF PC speed that exceeds 600 MHz, find OUT the average price OF PCs WITH identical speeds. RESULT SET: speed, average price.
  214.  
  215.     ~~~SQL
  216.     SELECT speed, avg(price)
  217.     FROM PC
  218.     WHERE speed > 600
  219.     GROUP BY speed;
  220.     ~~~
  221.  
  222. 23. GET the makers producing BOTH PCs HAVING a speed OF 750 MHz OR higher AND laptops WITH a speed OF 750 MHz OR higher. RESULT SET: maker
  223.  
  224.     ~~~SQL
  225.     SELECT DISTINCT maker
  226.     FROM Product, PC
  227.     WHERE Product.model = PC.model
  228.     AND speed >= 750
  229.     AND maker IN
  230.     (SELECT DISTINCT maker
  231.     FROM Product, Laptop
  232.     WHERE Product.model = Laptop.model
  233.     AND speed >= 750)
  234.     ~~~
  235.  
  236. 14. List the models OF any TYPE HAVING the highest price OF ALL products present IN the DATABASE.
  237.  
  238.     ~~~SQL
  239.     SELECT DISTINCT model
  240.     FROM
  241.     (SELECT model, price
  242.     FROM PC
  243.     UNION ALL
  244.     SELECT model, price
  245.     FROM Laptop
  246.     UNION ALL
  247.     SELECT model, price
  248.     FROM Printer) AS union_model
  249.     WHERE price >= ALL
  250.     (SELECT price FROM (
  251.     SELECT price FROM PC
  252.     UNION ALL
  253.     SELECT price FROM Laptop
  254.     UNION ALL
  255.     SELECT price FROM Printer) AS union_price);
  256.     ~~~
  257.  
  258. 15. Find the printer makers also producing PCs WITH the lowest RAM capacity AND the highest processor speed OF ALL PCs HAVING the lowest RAM capacity. RESULT SET: maker.
  259.  
  260.     ~~~SQL
  261.     SELECT DISTINCT maker
  262.     FROM Product, PC
  263.     WHERE Product.model = PC.model
  264.     AND ram =
  265.     (SELECT MIN(ram)
  266.     FROM PC)
  267.     AND speed =
  268.     (SELECT MAX(speed)
  269.     FROM PC
  270.     WHERE ram =
  271.     (SELECT MIN(ram)
  272.     FROM PC))
  273.     AND maker IN
  274.     (SELECT maker
  275.     FROM Product
  276.     WHERE TYPE='Printer');
  277.     ~~~
  278.  
  279. 16. Find OUT the average price OF PCs AND laptops produced BY maker A. RESULT SET: one overall average price FOR ALL items.
  280.  
  281.     ~~~SQL
  282.     SELECT avg(price)
  283.     FROM
  284.     (SELECT price
  285.     FROM Product, PC
  286.     WHERE Product.model = PC.model
  287.     AND maker = 'A'
  288.     UNION ALL
  289.     SELECT price
  290.     FROM Product, Laptop
  291.     WHERE Product.model = Laptop.model
  292.     AND maker='A'
  293.     ) AS union_price;
  294.     ~~~
  295.  
  296. 17. Find OUT the average hard disk drive capacity OF PCs produced BY makers who also manufacture printers.
  297.     RESULT SET: maker, average HDD capacity.
  298.  
  299.     ~~~SQL
  300.     SELECT maker, avg(hd)
  301.     FROM Product, PC
  302.     WHERE Product.model = PC.model
  303.     AND maker IN
  304.     (SELECT DISTINCT maker
  305.     FROM Product
  306.     WHERE TYPE='printer')
  307.     GROUP BY maker;
  308.     ~~~
  309.  
  310. 18. Determine the average quantity OF paint per square WITH an accuracy OF two DECIMAL places.
  311.  
  312.     ~~~SQL
  313.     SELECT
  314.     round(SUM(ifnull(B_VOL,0))/COUNT(DISTINCT Q_ID),2)
  315.     FROM utB RIGHT JOIN utQ
  316.     ON utB.B_Q_ID = utQ.Q_ID;
  317.     ~~~
  318.  
  319. 19. UNDER the assumption that receipts OF money (inc) AND payouts (OUT) are registered NOT more than once a DAY FOR each collection point [i.e. the PRIMARY KEY consists OF (point, DATE)], WRITE a query displaying cash flow DATA (point, DATE, income, expense).
  320.     USE Income_o AND Outcome_o TABLES.
  321.  
  322.     ~~~SQL
  323.     SELECT i.point, i.DATE, i.inc, o.OUT
  324.     FROM Income_o i LEFT JOIN Outcome_o o
  325.     ON i.point = o.point
  326.     AND i.DATE = o.DATE
  327.     UNION
  328.     SELECT o.point, o.DATE, i.inc, o.OUT
  329.     FROM Outcome_o o LEFT JOIN Income_o i
  330.     ON o.point = i.point
  331.     AND o.DATE = i.DATE
  332.     ~~~
  333.  
  334. 10. UNDER the assumption that receipts OF money (inc) AND payouts (OUT) can be registered any NUMBER OF times a DAY FOR each collection point [i.e. the code COLUMN IS the PRIMARY KEY], display a TABLE WITH one corresponding ROW FOR each operating DATE OF each collection point.
  335.     RESULT SET: point, DATE, total payout per DAY (OUT), total money intake per DAY (inc).
  336.     Missing VALUES are considered TO be NULL.
  337.  
  338.     ~~~SQL
  339.     SELECT i.point, i.DATE, o.OUT, i.inc
  340.     FROM
  341.     (SELECT point, DATE, SUM(inc) AS inc
  342.     FROM Income
  343.     GROUP BY point, DATE) i
  344.     LEFT JOIN
  345.     (SELECT point, DATE, SUM(OUT) AS OUT
  346.     FROM Outcome
  347.     GROUP BY point, DATE) o
  348.     ON i.point = o.point
  349.     AND i.DATE = o.DATE
  350.     UNION
  351.     SELECT o.point, o.DATE, o.OUT, i.inc
  352.     FROM
  353.     (SELECT point, DATE, SUM(OUT) AS OUT
  354.     FROM Outcome
  355.     GROUP BY point, DATE) o
  356.     LEFT JOIN
  357.     (SELECT point, DATE, SUM(inc) AS inc
  358.     FROM Income
  359.     GROUP BY point, DATE) i
  360.     ON o.point = i.point
  361.     AND o.DATE = i.DATE;
  362.     ~~~
  363.  
  364. 11. FOR ship classes WITH a gun caliber OF 16 IN. OR more, display the class AND the country.
  365.  
  366.     ~~~SQL
  367.     SELECT class, country
  368.     FROM Classes
  369.     WHERE bore >= 16;
  370.     ~~~
  371.  
  372. 12. One OF the characteristics OF a ship IS one-half the cube OF the calibre OF its main guns (mw).
  373.     Determine the average.
  374.  
  375.     ~~~SQL
  376.     SELECT country, round(avg(POWER(bore,3)*0.5),2)
  377.     FROM
  378.     (SELECT country, bore, name
  379.     FROM Classes, Ships
  380.     WHERE Classes.class = Ships.class
  381.     UNION
  382.     SELECT country, bore, ship
  383.     FROM Classes, Outcomes
  384.     WHERE Classes.class = Outcomes.ship
  385.     ) AS new_ships
  386.     GROUP BY country;
  387.     ~~~
  388.  
  389. 13. GET the ships sunk IN the North Atlantic battle.
  390.     RESULT SET: ship.
  391.  
  392.     ~~~SQL
  393.     SELECT ship
  394.     FROM Outcomes
  395.     WHERE battle = 'North Atlantic'
  396.     AND RESULT = 'sunk';
  397.     ~~~
  398.  
  399. 14. IN accordance WITH the Washington Naval Treaty concluded IN the beginning OF 1922, it was prohibited TO build battle ships WITH a displacement OF more than 35 thousand tons.
  400.     GET the ships violating this treaty (ONLY consider ships FOR which the YEAR OF launch IS known).
  401.     List the names OF the ships.
  402.  
  403.     ~~~SQL
  404.     SELECT DISTINCT name
  405.     FROM Ships, Classes
  406.     WHERE Ships.class = Classes.class
  407.     AND TYPE = 'bb'
  408.     AND displacement > 35000
  409.     AND launched >= 1922;
  410.     ~~~
  411.  
  412. 15. Find models IN the Product TABLE consisting either OF digits ONLY OR Latin letters (A-Z, CASE insensitive) ONLY.
  413.     RESULT SET: model, TYPE.
  414.  
  415.     ~~~SQL
  416.     SELECT model, TYPE
  417.     FROM Product
  418.     WHERE model REGEXP '^(([0-9]+)|([a-zA-Z]+))$';
  419.     ~~~
  420.  
  421. 16. List the names OF lead ships IN the DATABASE (including the Outcomes TABLE).
  422.  
  423.     ~~~SQL
  424.     SELECT name
  425.     FROM Ships
  426.     WHERE name IN
  427.     (SELECT class
  428.     FROM Classes)
  429.     UNION
  430.     SELECT ship
  431.     FROM Outcomes
  432.     WHERE ship IN
  433.     (SELECT class
  434.     FROM Classes);
  435.     ~~~
  436.  
  437. 17. Find classes FOR which ONLY one ship EXISTS IN the DATABASE (including the Outcomes TABLE).
  438.  
  439.     ~~~SQL
  440.     SELECT class
  441.     FROM
  442.     (SELECT Classes.class, name
  443.     FROM Classes, Ships
  444.     WHERE Classes.class = Ships.class
  445.     UNION
  446.     SELECT class, ship AS name
  447.     FROM Classes, Outcomes
  448.     WHERE Classes.class = Outcomes.ship
  449.     ) AS full_ship
  450.     GROUP BY class
  451.     HAVING COUNT(*) = 1;
  452.     ~~~
  453.  
  454. 18. Find countries that ever had classes OF BOTH battleships (‘bb’) AND cruisers (‘bc’).
  455.  
  456.     ~~~SQL
  457.     SELECT DISTINCT country
  458.     FROM Classes
  459.     WHERE TYPE='bb'
  460.     AND country IN
  461.     (SELECT DISTINCT country
  462.     FROM Classes
  463.     WHERE TYPE='bc');
  464.     ~~~
  465.  
  466. 19. Find the ships that "survived for future battles"; that IS, after being damaged IN a battle, they participated IN another one, which occurred later.
  467.  
  468.     ~~~SQL
  469.     SELECT DISTINCT o2.ship FROM
  470.     (SELECT ship, battle, RESULT, DATE
  471.     FROM Outcomes, Battles
  472.     WHERE Outcomes.battle = Battles.name
  473.     AND RESULT='damaged'
  474.     ) AS o1,
  475.     (SELECT ship, battle, RESULT, DATE
  476.     FROM Outcomes, Battles
  477.     WHERE Outcomes.battle = Battles.name
  478.     ) AS o2
  479.     WHERE o1.ship = o2.ship
  480.     AND o1.DATE < o2.DATE;
  481.     ~~~
  482.  
  483. 10. FOR the ships IN the Ships TABLE that have at least 10 guns, GET the class, name, AND country.
  484.  
  485.     ~~~SQL
  486.     SELECT Ships.class, name, country
  487.     FROM Ships LEFT JOIN Classes
  488.     ON Ships.class = Classes.class
  489.     WHERE numGuns >= 10;
  490.     ~~~
  491.  
  492. 11. FOR the PC IN the PC TABLE WITH the maximum code VALUE, obtain ALL its characteristics (EXCEPT FOR the code) AND display them IN two COLUMNS: name OF the characteristic (title OF the corresponding COLUMN IN the PC TABLE);its respective VALUE.
  493.  
  494.     ~~~SQL
  495.     SELECT 'model', model
  496.     FROM PC
  497.     WHERE code=
  498.     (SELECT MAX(code)
  499.     FROM PC)
  500.     UNION
  501.     SELECT 'speed', speed
  502.     FROM PC
  503.     WHERE code=
  504.     (SELECT MAX(code)
  505.     FROM PC)
  506.     UNION
  507.     SELECT 'ram', ram
  508.     FROM PC
  509.     WHERE code=
  510.     (SELECT MAX(code)
  511.     FROM PC)
  512.     UNION
  513.     SELECT 'hd', hd
  514.     FROM PC
  515.     WHERE code=
  516.     (SELECT MAX(code)
  517.     FROM PC)
  518.     UNION
  519.     SELECT 'cd', cd
  520.     FROM PC
  521.     WHERE code=
  522.     (SELECT MAX(code)
  523.     FROM PC)
  524.     UNION
  525.     SELECT 'price', price
  526.     FROM PC
  527.     WHERE code=
  528.     (SELECT MAX(code)
  529.     FROM PC)
  530.     ~~~
  531.  
  532. 12. Find the names OF ships sunk at battles, along WITH the names OF the corresponding battles.
  533.  
  534.     ~~~SQL
  535.     SELECT ship, battle
  536.     FROM Outcomes
  537.     WHERE RESULT='sunk';
  538.     ~~~
  539.  
  540. 13. GET the battles that occurred IN years WHEN no ships were launched INTO water.
  541.  
  542.     ~~~SQL
  543.     SELECT name
  544.     FROM Battles
  545.     WHERE YEAR(DATE)
  546.     NOT IN
  547.     (SELECT launched
  548.     FROM Ships
  549.     WHERE launched IS NOT NULL);
  550.     ~~~
  551.  
  552. 14. Find ALL ship names beginning WITH the letter R.
  553.  
  554.     ~~~SQL
  555.     SELECT name
  556.     FROM Ships
  557.     WHERE name LIKE 'R%'
  558.     UNION
  559.     SELECT ship
  560.     FROM Outcomes
  561.     WHERE ship LIKE 'R%';
  562.     ~~~
  563.  
  564. 15. Find ALL ship names consisting OF three OR more words (e.g., King George V).
  565.     Consider the words IN ship names TO be separated BY single spaces, AND the ship names TO have no LEADING OR TRAILING spaces.
  566.  
  567.     ~~~SQL
  568.     SELECT name
  569.     FROM Ships
  570.     WHERE name LIKE '% % %'
  571.     UNION
  572.     SELECT ship
  573.     FROM Outcomes
  574.     WHERE ship LIKE '% % %';
  575.     ~~~
  576.  
  577. 16. FOR each ship that participated IN the Battle OF Guadalcanal, GET its name, displacement, AND the NUMBER OF guns.
  578.  
  579.     ~~~SQL
  580.     SELECT DISTINCT ship, displacement, numguns
  581.     FROM Classes LEFT JOIN Ships
  582.     ON classes.class=ships.class
  583.     RIGHT JOIN Outcomes
  584.     ON Classes.class=ship
  585.     OR ships.name=ship
  586.     WHERE battle='Guadalcanal';
  587.     ~~~
  588.  
  589. 1.  NUMBER the ROWS OF the Product TABLE AS follows: makers IN descending ORDER OF NUMBER OF models produced BY them (FOR manufacturers producing an equal NUMBER OF models, their names are sorted IN ascending alphabetical ORDER); model numbers IN ascending ORDER.
  590.     RESULT SET: ROW NUMBER AS described above, manufacturer's name (maker), model.
  591.  
  592.    ~~~sql
  593.    select count(*) num, t1.maker, t1.model
  594.    from (
  595.    select maker, model, c
  596.    from Product
  597.    join (
  598.    select count(model) c, maker m
  599.    from Product
  600.    group by maker ) b1
  601.    on maker = m) t1
  602.    join
  603.    (select maker, model, c
  604.    from Product
  605.    join (
  606.    select count(model) c, maker m
  607.    from Product
  608.    group by maker ) b2
  609.    on maker = m) t2
  610.    on t2.c > t1.c
  611.    or t2.c=t1.c and t2.maker<t1.maker
  612.    or t2.c=t1.c and t2.maker=t1.maker and t2.model <= t1.model
  613.    group by t1.maker, t1.model
  614.    order by 1;
  615.    ~~~
  616.  
  617. 2.  Find the ship classes having at least one ship sunk in battles.
  618.  
  619.    ~~~sql
  620.    select distinct Classes.class
  621.    from Classes, Ships, Outcomes
  622.    where Classes.class = Ships.class
  623.    and Ships.name = Outcomes.ship
  624.    and Outcomes.result = 'sunk'
  625.    union
  626.    select distinct class
  627.    from Classes, Outcomes
  628.    where Classes.class = Outcomes.ship
  629.    and Outcomes.result = 'sunk';
  630.    ~~~
  631.  
  632. 3.  Find the names of the ships having a gun caliber of 16 inches (including ships in the Outcomes table).
  633.  
  634.    ~~~sql
  635.    select name
  636.    from Ships, Classes
  637.    where Ships.class = Classes.class
  638.    and bore = 16
  639.    union
  640.    select ship
  641.    from Outcomes, Classes
  642.    where Outcomes.ship = Classes.class
  643.    and bore = 16;
  644.    ~~~
  645.  
  646. 4.  Find the battles in which Kongo-class ships from the Ships table were engaged.
  647.  
  648.    ~~~sql
  649.    select battle
  650.    from Outcomes, Ships
  651.    where Outcomes.ship = Ships.name
  652.    and Ships.class = 'Kongo';
  653.    ~~~
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement