以下のSQLに関するこの質問を参考にして、各チームのトップ5レングスを合計しました。私にとって今の問題は、SQLは無作為に5つのデータベース(例えば25行目、5行目は5行目)をランダムに選択しているようです。多くのappriciatedだろう!SQL各チームの上位5行を合計します
select team, sum(length) as totalScore
from
(
SELECT
t.*,
@num_in_group:=case when @team!=team then @num_in_group:=0 else @num_in_group:[email protected]_in_group+1 end as num_in_group,
@team:=team as t
FROM reg_catches t, (select @team:=-1, @num_in_group:=0) init
ORDER BY team asc
) sub
WHERE
sub.num_in_group <= 4 and
competition = 16 and
team = 25
GROUP BY team
ORDER BY totalScore DESC;
表
team length competition
----------------------
26 70 16
25 70 16
25 95 16
25 98 16
25 100 16
25 100 16
25 100 16
25 122 16
募集出力:
team totalScore
---- -----------
25 520
26 70
敬具、あなたの内側のクエリで クリスチャン
表の主キーはありませんか? –
@PaulSpiegel私たちがすでに持っているデータの上にプライマリキーがなぜ役立つのでしょうか? –
@TimBiegeleisenあなたはあなた自身の答えでそれを書いた: "ネクタイを壊すために他の列"。 –