Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Three ships

737286Feb 25 2010 — edited Mar 25 2010
Hi All,

Could you please help me with the following problem:

Delete the classes having less than three ships in database (taking into account Outcomes table).

Below is the description of the database:
The database of naval ships that took part in World War II is under consideration. The database has the following relations:
Classes(class, type, country, numGuns, bore, displacement)
Ships(name, class, launched)
Battles(name, date)
Outcomes(ship, battle, result)
Ships in classes are arranged to a single project. A class is normally assigned the name of the first ship in the class under consideration (head ship); otherwise, the class name does not coincide with any ship name in the database.
The Classes relation includes the class name, type (bb for a battle ship, or bc for a battle cruiser), country where the ship was built, number of main guns, gun caliber (diameter of the gun barrel, in inches), and displacement (weight in tons). The Ships relation includes the ship name, its class name, and launch year. The Battles relation covers the name and date of a battle the ships participated; while the result of their participation in the battle (sunk, damaged, or unharmed - OK) is in the Outcomes relation. Note: the Outcomes relation may include the ships not included in the Ships relation.

My solution is :
delete from classes
where class in (
select s.class from ships s, classes c
where c.class=s.class
group by s.class
having count(s.class) < 3
UNION
select o.ship from outcomes o, classes c
where c.class=o.ship
group by o.ship
having count(o.ship) < 3
)

But unfortunately I produced correct result set on main database, but it failed test on second, checking database.

Thank you in advance,
Ann

Edited by: user8105261 on Mar 25, 2010 4:01 PM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 25 2010
Added on Feb 25 2010
3 comments
1,102 views