csdn老系统错误,虽然cnblogs不关心T-SQL,但我想这里一定有人懂
两个表
正确答案是
请问怎么查?(就是查具有同一battleName的country)
还有
我用
select country,count(*)as numsunk
from ships join Battles on ships.name=Battles.ship
where battleName='Surigao Strait'
and result='sunk'
group by country
查出
但正确答案是
我的把USA搞没了
怎么解决谢谢
虽然不干.NET事,请不要怪,百度了N天没结果
两个表
Table: Ships
name | yearLaunched | country | numGuns | gunSize | displacement |
Bismarck | 1940 | Germany | 8 | 15 | 42000 |
Oktyabrskaya Revolutsia | 1914 | USSR | 12 | 12 | 23000 |
Warspite | 1915 | Great Britain | 8 | 15 | 31000 |
Hood | 1920 | Great Britain | 8 | 15 | 41000 |
Nelson | 1927 | Great Britain | 9 | 16 | 34000 |
Prince of Wales | 1941 | Great Britain | 10 | 14 | 38000 |
Giulio Cesare | 1914 | Italy | 10 | 13 | 24000 |
Texas | 1914 | USA | 10 | 14 | 27000 |
Arizona | 1916 | USA | 12 | 14 | 33000 |
California | 1921 | USA | 12 | 14 | 32000 |
West Virginia | 1923 | USA | 8 | 16 | 32000 |
New Jersey | 1943 | USA | 9 | 16 | 46000 |
Missouri | 1944 | USA | 9 | 16 | 46000 |
Kirishima | 1915 | Japan | 8 | 14 | 32000 |
Fuso | 1915 | Japan | 12 | 14 | 35000 |
Yamashiro | 1917 | Japan | 12 | 14 | 35000 |
Nagato | 1920 | Japan | 8 | 16 | 38000 |
Yamato | 1941 | Japan | 9 | 18 | 65000 |
Musashi | 1942 | Japan | 9 | 18 | 65000 |
Table: Battles
ship | battleName | result |
Fuso | Surigao Strait | sunk |
Yamashiro | Surigao Strait | sunk |
California | Surigao Strait | ok |
West Virginia | Surigao Strait | ok |
Bismarck | North Atlantic | sunk |
Hood | North Atlantic | sunk |
Prince of Wales | North Atlantic | damaged |
其中ships.name=battles,ship
我用
select distinct ships.country ,Battles.battleName,ships.country from ships right join Battles on ships.name=Battles.ship
查出下面结果
country | battleName | country |
Japan | Surigao Strait | Japan |
USA | Surigao Strait | USA |
Germany | North Atlantic | Germany |
Great Britain | North Atlantic | Great Britain |
正确答案是
country | country |
Japan | USA |
Germany | Great Britain |
请问怎么查?(就是查具有同一battleName的country)
还有
我用
select country,count(*)as numsunk
from ships join Battles on ships.name=Battles.ship
where battleName='Surigao Strait'
and result='sunk'
group by country
查出
country | numsunk |
Japan | 2 |
但正确答案是
country | numSunk |
Japan | 2 |
USA | 0 |
怎么解决谢谢
虽然不干.NET事,请不要怪,百度了N天没结果