1

テーブル構造:

country
season
points

現在のクエリ:

SELECT SUM(points) AS total, country 
FROM table 
WHERE season >= X 
GROUP BY country 
ORDER BY total desc

これにより、特定の国で収集された合計ポイントで並べ替えられた素敵なリストが得られます。しかし、ある国が別の国と結ばれている場合、指定された最新シーズンのポイントで並べ替えたいのですが、同じクエリ内で可能ですか? もしそうなら、どのように?(現時点でグループ化されていることを思い出してください)

行の例 デンマーク (国)、1 (季節)、10 (ポイント) デンマーク (国)、2 (季節)、5 (ポイント) スウェーデン (国)、1 (季節)、5 (ポイント) スウェーデン (国)、 2 (シーズン)、10 (ポイント)

4

2 に答える 2

1
SELECT grp.total, grp.country
FROM
        ( SELECT SUM(points) AS total, country, MAX(season) AS max_season 
          FROM table 
          WHERE season >= X 
          GROUP BY country 
        ) AS grp
    LEFT JOIN
        table AS t
            ON  t.country = grp.country
            AND t.season = LATEST_SEASON
ORDER BY 
    grp.total DESC
  , t.points DESC ;   
于 2012-07-11T09:50:12.803 に答える
1

多分これはあなたのトリックを行うでしょう:

SELECT SUM(points) AS total, country 
FROM table 
WHERE season >= X 
GROUP BY country 
ORDER BY total DESC, (SELECT t2.points FROM table t2 WHERE table.country=t2.country ORDER BY t2.season LIMIT 1) DESC
于 2012-07-11T09:50:32.100 に答える