database - SQL Query: ships with second biggest gun size -
i need query. problem have 2 schemas battleships , battles fought in: ships(name, yearlaunched, country, numguns, gunsize, displacement) battles(ship, battlename, result) question following: write query in battleships had guns second largest gun size. more precisely, find ships gun size exceeded 1 gun size, no matter how many other ships had larger gun size. list names of ships , gun size. attempted solve problem , answer following:
select smax.name, smax.gunsize ships smax ((select s.name,s.gunsize ships s s.gunsize not exists ( select ss.gunsize ships ss ss.gunsize >= all(select ss1.gunsize ships ss1))) temp) , smax.gunsize >= (select temp.gunsize ships temp)
thank taking time read , answer !
try following:
select name, gunsize ships gunsize=( select max(gunsize) secondbiggest ships gunsize<(select max(gunsize) biggest ships) )
edit: hint: secondbiggest
, biggest
aliases used clarifying each subquery does.
Comments
Post a Comment