MySQL
SELECT
t.*
FROM
row_table t
INNER JOIN (
SELECT
class,
GROUP_CONCAT(student ORDER BY score DESC) grouped_student
FROM
row_table
GROUP BY class) group_max
ON t.class = group_max.class
AND FIND_IN_SET(student, grouped_student) BETWEEN 1 AND 2;
Slide 13
Slide 13 text
MySQL
SELECT
t.*
FROM
row_table t
INNER JOIN (
SELECT
class,
GROUP_CONCAT(student ORDER BY score DESC) grouped_student
FROM
row_table
GROUP BY class) group_max
ON t.class = group_max.class
AND FIND_IN_SET(student, grouped_student) BETWEEN 1 AND 2;
GROUP_CONCATͰ
Ϋϥε͝ͱʹιʔτͯ͠
Slide 14
Slide 14 text
MySQL
SELECT
t.*
FROM
row_table t
INNER JOIN (
SELECT
class,
GROUP_CONCAT(student ORDER BY score DESC) grouped_student
FROM
row_table
GROUP BY class) group_max
ON t.class = group_max.class
AND FIND_IN_SET(student, grouped_student) BETWEEN 1 AND 2;
FIND_IN_SETͰ
ઌ಄͚ͩऔΓग़͢
GROUP_CONCATͰ
Ϋϥε͝ͱʹιʔτͯ͠
Slide 15
Slide 15 text
Presto
Hive
PostgreSQL
SELECT
*
FROM (
SELECT
*,
rank() over (partition by class order by score desc) as rank
FROM row_table
) t
WHERE rank <= 2
Slide 16
Slide 16 text
Presto
Hive
PostgreSQL
SELECT
*
FROM (
SELECT
*,
rank() over (partition by class order by score desc) as rank
FROM row_table
) t
WHERE rank <= 2
rank()ͰΫϥεͰͷ
ॱҐΛ͚ͭͯ
Slide 17
Slide 17 text
Presto
Hive
PostgreSQL
SELECT
*
FROM (
SELECT
*,
rank() over (partition by class order by score desc) as rank
FROM row_table
) t
WHERE rank <= 2
rank()ͰΫϥεͰͷ
ॱҐΛ͚ͭͯ
2ҐҎ্ͷਓ͚ͩൈ͖ग़͢
Slide 18
Slide 18 text
SELECT
each_top_k(
2, class, score,
student,
class
) as (rank, score, student, class)
FROM
(SELECT * FROM raw_table DISTRIBUTE BY class SORT BY class) t
Hivemall
Slide 19
Slide 19 text
SELECT
each_top_k(
2, class, score,
student,
class
) as (rank, score, student, class)
FROM
(SELECT * FROM raw_table DISTRIBUTE BY class SORT BY class) t
Hivemall
Ϋϥε͝ͱʹϊʔυΛ
ࢄ͠ιʔτ
Slide 20
Slide 20 text
SELECT
each_top_k(
2, class, score,
student,
class
) as (rank, score, student, class)
FROM
(SELECT * FROM raw_table DISTRIBUTE BY class SORT BY class) t
Hivemall
Ϋϥε͝ͱʹϊʔυΛ
ࢄ͠ιʔτ
each_top_kͰ্ҐͷΈநग़