1

演習 39: 「将来の戦闘で生き残った」船を定義します。ある戦いで損傷を受け、別の戦いに参加しました。

データベース スキーマ: http://www.sql-ex.ru/help/select13.php#db_3

私のアプローチ:

SELECT distinct o.ship from Outcomes o
WHERE o.RESULT = 'damaged' 
AND exists (select 1 FROM Outcomes o2 WHERE o2.ship = o.ship 
AND (o2.result='OK' OR o2.result='sunk'))

sql-ex 言う

あなたのクエリはメインデータベースで正しい結果セットを生成しましたが、データベースをチェックして2番目のテストに失敗しました

私の出力と一致した正しい結果。

どこで失敗しましたか?

4

6 に答える 6

2

解決しました!Distinct を追加する必要があります

select distinct kk.ship from
(Select ship,date from outcomes oo,battles bb where oo.battle=bb.name) tt 
inner join 
(Select ship,date as damagedate from outcomes oo,battles bb where result='damaged' AND oo.battle=bb.name) kk 
ON tt.ship=kk.ship AND tt.date>kk.damagedate
于 2016-03-29T07:19:56.443 に答える
1
with a as (select * from outcomes o join battles b on o.battle=b.name)select distinct a1.ship from a a1, a a2 where a1.ship=a2.ship and a1.result='damaged'and a1.date<a2.date
于 2013-12-13T06:46:52.043 に答える
0
select distinct outcomes.ship
from outcomes, (select outcomes.ship, battles.[date], outcomes.result
            from outcomes, battles
            where battles.name = outcomes.battle
            and result = 'damaged' ) t1, 
 battles
where outcomes.ship = t1.ship and
outcomes.battle = battles.name and
battles.[date] > t1.[date]
于 2015-06-09T12:56:09.453 に答える
0

これが私の答えです。ページでは真実として解決されていませんが、私はそれに同意していません。私の解決策があなたの解決策と何が違うのかわかりません

select distinct damaged.ship from 
(Select oo.ship,date from outcomes oo
inner join battles bb on oo.battle=bb.name
) as ships
inner join (Select ship,date as damagedate from outcomes oo1
inner join battles bb1 on oo1.battle=bb1.name and result = 'damaged') as damaged
on (ships.ship = damaged.ship and ships.date != damaged.damagedate)
于 2016-10-06T11:44:03.130 に答える