SQL FIDDLEに配置された以下のようなテーブルがあります
id empid proj file rating
~~ ~~~~~ ~~~~ ~~~~ ~~~~~~
1 1863 G1 file1 1
2 P4645 G1 file2 1
3 P6682 G1 file3 1
4 P6682 G1 file4 1
5 P4645 G1 file5 1
6 P4645 G1 file6 1
7 1863 G1 file7 1
8 1863 G1 file8 1
9 1863 G1 file19 1
10 P6682 G2 file21 1
11 1863 G2 file55 1
12 P6682 G2 file60 1
13 P4645 G2 file85 1
14 P6682 G2 file91 1
15 P4645 G2 file93 1
16 P4645 G3 file95 1
17 P4645 G3 file100 1
18 P4645 G3 file125 1
19 1863 G3 file131 1
20 1863 G3 file150 1
21 P6682 G3 file193 1
21 P6682 G3 file193 1
上記の表から各カテゴリ (proj) の上位 n (たとえば上位 2) の評価数を取得するには、SQL が必要です。
希望OPは以下の通り
proj empid ratings
~~~~ ~~~~~ ~~~~~~~
G1 1863 4
G1 P4645 3
G2 P6682 3
G2 P4645 2
G3 P4645 3
G3 1863 2
G3 P6682 2
このスレッドの方法に従おうとしましたが、私が持っているテーブルのデザインから達成できませんでした。