SQL Asslgnment The shema of these relations is: CLASSES(class, type, country, nu
ID: 3586447 • Letter: S
Question
SQL Asslgnment The shema of these relations is: CLASSES(class, type, country, numguns, bore, displacement) SHIPS (name, class, launched) BATTLES (name. date) OUTCOMES (ship, battle, result) Ships are built in "classes" from the same design, and the class is usually named for the first ship of that class. The relation Classes records the name of the class, the type(bb' for battleship or 'bc' for battlecruiser), the country that build the ship, the number of main guns, the bore (diameter of the gun), and the displacement(weight, in tons). Relation Ships records the name of the ship, the name of its class, and the year in which the ship was launched. Relation Battles gives the name and date of battles involving these ships, and relation Outcomes gives the result (sunk, damaged, or ok) for each in each battle The Assignment write the necessary sql queries for the folowing tasks. 1. The average bore of battleship classes (type- bb') 2. The average bore of all battleships (type- bb), and their total number of guns. This 3. 4. average should be different from the 1st query, why? The number of ships involved in each battle. The number of battles in which each ship participated, if more than 1.Explanation / Answer
1. select avg(class) from CLASSES where type='bb';
2. select avg(type),sum(numguns) from CLASSES where type='bb' ;
Because in the first query average of classes of type bb is asked. But in this average of type bb is asked . So that's why both queris averages will be different.
3. select count(ship) from OUTCOMES,SHIPS s,BATTLES b where ship=s.name and battle=b.name;
4. select count(battle) from OUTCOMES,SHIPS s,BATTLES b where ship=s.name and battle=b.name having count(battle)>1;
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.