陸上競技用の 11 列のテーブルがあり、特定のイベント、年齢層、性別でテーブルを並べ替え、すべての重複を取り出し、最良の結果を保持する SQL クエリを作成しました。一部のイベントでは、風が特定の速度を超えている場合と同様に、風が読み取られた結果と読み取られなかった結果も区別されます。
@export on;
@export set filename="/home/filename.csv" CsvColumnDelimiter=",";
select * from Results2015;
SELECT resu.Result,
resu.Wind,
resu.`Full Name`,
resu.Province,
resu.BirthDate,
resu.Position,
resu.Location,
resu.Date
FROM Results2015 resu
JOIN (
SELECT MIN(Result) BestResult,
Wind, `Full Name`, Gender,
Event, Agegroup
FROM Results2015
GROUP BY `Full Name`, Gender, Event, Agegroup
) best
ON resu.Result = best.BestResult
AND resu.Wind = best.Wind
AND resu.`Full Name` = best.`Full Name`
AND resu.Gender = best.Gender
AND resu.Event = best.Event
AND resu.Agegroup = best.Agegroup
WHERE resu.Event = '100m'
AND resu.Gender = 'F'
AND resu.Agegroup = 'Junior'
AND resu.Wind <> ''
AND resu.Wind <= 2
ORDER BY resu.Result asc;
それは非常にうまく機能しますが、風の測定値を含む多くの結果が欠落していることに気付きました。その理由はわかりません. これが私が使用するテーブルのサンプルです
Result Wind Full Name Province BirthDate Position Location Date Event Gender Agegroup
12.78 -3.6 Name 4 WPA D.o.B 6 Bellville 3-Feb 100m F Junior
12.87 -3.6 Name 2 WPA D.o.B 7 Bellville 8-Feb 100m M Youth
12.64 -0.8 Name 3 WPA D.o.B 2 Bellville 8-Feb 100m F Junior
12.02 -0.8 Name 4 WPA D.o.B 1 Bellville 8-Feb 100m F Junior
12.84 -0.8 Name 5 WPA D.o.B 3 Bellville 8-Feb 100m F Junior
13.07 -0.8 Name 6 WPA D.o.B 4 Bellville 8-Feb 100m F Junior
13.23 -0.8 Name 7 WPA D.o.B 5 Bellville 8-Feb 100m F Junior
13.71 -4.3 Name 8 WPA D.o.B 1 Bellville 8-Feb 100m F Junior
13.85 -4.3 Name 9 WPA D.o.B 2 Bellville 8-Feb 100m F Junior
14.33 -4.3 Name 10 WPA D.o.B 3 Bellville 8-Feb 100m F Junior
14.69 Name 11 WPA D.o.B 4 Bellville 2-Feb 100m F Junior
13.11 -2.9 Name 12 WPA D.o.B 1 Bellville 8-Feb 100m F Sub-Youth
13.43 -2.9 Name 13 WPA D.o.B 2 Bellville 8-Feb 100m F Sub-Youth
13.53 -2.9 Name 12 WPA D.o.B 3 Bellville 14-Feb 100m F Sub-Youth
13.60 -1.5 Name 15 WPA D.o.B 1 Bellville 14-Feb 100m F Sub-Youth
何らかの理由で、出力で Name 4 を完全にスキップします。名前 4 のデータは他のエントリとまったく同じであり、それらを表示しますが、名前 4 と他のエントリは完全に除外されますが、私が知る限り風読みがあるものだけです。
GROUP BY の部分に Wind を追加すると
GROUP BY `Full Name`, Gender, Event, Agegroup, Wind
すべて正しい結果が表示されますが、避けたい重複がたくさんあります。
何が起こっているかについて何か考えはありますか?
すべての SQL クエリに DbVisualizer Pro を使用しています
SQLFiddle サンプルはこちらhttp://www.sqlfiddle.com/#!2/f8958/1 問題は、Tamza Bay が出力に表示されないことにあります