WITH
    ranked_scores AS (
        SELECT
            t1.score,
            t2.tag,
            RANK() OVER (
                ORDER BY
                    t1.score ASC
            ) AS score_rank
        FROM
            exam_record t1
            JOIN examination_info t2 USING (exam_id)
        WHERE
            t2.tag = 'SQL'
            AND t1.score >= (
                SELECT
                    AVG(t3.score)
                FROM
                    exam_record t3
                    JOIN examination_info t4 USING (exam_id)
                WHERE
                    t4.tag = 'SQL'
            )
    )
SELECT
    score
FROM
    ranked_scores
WHERE
    score_rank = 1;