这样尝试
SELECt DISTINCT LEAST(s1.country, s2.country) c1, GREATEST(s1.country, s2.country) c2 FROM battles b1 JOIN battles b2 ON b1.battlename = b2.battlename AND b1.ship <> b2.ship JOIN ships s1 ON b1.ship = s1.name JOIN ships s2 ON b2.ship = s2.nameHAVINg c1 <> c2
输出:
| C1 | C2 ||---------|---------------|| Germany | Great Britain || Japan |USA |
这是 SQLFiddle 演示
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)