0
私は、athlete_ids、スポーツ、ゴールド、シルバー、ブロンズの5つのフィールドを持つアスリートというテーブルを持っています。このテーブルから、most_played_sportsというビューを作成します。このビューには、500人以上のアスリートを持つすべてのスポーツが含まれています。現在の課題は、上記のビューを使用してsport_1のメダル数がsport_2よりも厳密に少ないような異なる種類のスポーツ(sport_1、sport_2)を見つけることです。SQLiteクエリがぶら下がっています
私が試したクエリは次のとおりです。
create view if not exists most_played_sports as select sport, sum(gold)+sum(silver)+sum(bronze) as medal_count from athletes
group by sport
having count(id) >= 500;
select distinct athletes.sport as sport_1, most_played_sports.sport as sport_2
from athletes cross join most_played_sports
where sport_1 > sport_2 and
((select medal_count from most_played_sports where sport=sport_1) < (select medal_count from most_played_sports where sport=sport_2));
2番目のクエリは、いくつかの結果を返しているが、ぶら下がっています。私が試したことよりもこの作業を行う良い方法はありますか?