CREATE TABLE ndecoreexcel_math_grade8 (year NUMBER, state CLOB, all_students CLOB, average_scale_score NUMBER)
CREATE TABLE finrev_fed_17 (state_code NUMBER, idcensus NUMBER, school_district CLOB, nces_id CLOB, yr_data NUMBER, t_fed_rev NUMBER, c14 NUMBER, c25 NUMBER)
CREATE TABLE finrev_fed_key_17 (state_code NUMBER, state CLOB)

What are the schools with highest federal revenue in each federal revenue categories and what's their state average scores?
SELECT T1.school_district, MAX(T1.c14), T3.average_scale_score FROM finrev_fed_17 AS T1 JOIN finrev_fed_key_17 AS T2 ON T1.state_code = T2.state_code JOIN ndecoreexcel_math_grade8 AS T3 ON T2.state = T3.state UNION SELECT T1.school_district, MAX(T1.c25), T3.average_scale_score FROM finrev_fed_17 AS T1 JOIN finrev_fed_key_17 AS T2 ON T1.state_code = T2.state_code JOIN ndecoreexcel_math_grade8 AS T3 ON T2.state = T3.state
SELECT "T1"."school_district", MAX("T1"."c14"), "T3"."average_scale_score" FROM "finrev_fed_17" "T1" JOIN "finrev_fed_key_17" "T2" ON "T1"."state_code" = "T2"."state_code" JOIN "ndecoreexcel_math_grade8" "T3" ON "T2"."state" = "T3"."state" UNION SELECT "T1"."school_district", MAX("T1"."c25"), "T3"."average_scale_score" FROM "finrev_fed_17" "T1" JOIN "finrev_fed_key_17" "T2" ON "T1"."state_code" = "T2"."state_code" JOIN "ndecoreexcel_math_grade8" "T3" ON "T2"."state" = "T3"."state"