We have a school district with 38 elementary schools. Children passed the test. The average values ββfor schools are widely scattered, but I want to compare the average values ββONLY TOP 10 students from each school.
Requirement: Use only temporary tables.
I made this a very time-consuming, error-prone way, as follows. (sch_code = e.g. 9043; - schabbrev = e.g. "Carter"; - totpct_stu = e.g. 61.3)
DROP TEMPORARY TABLE IF EXISTS avg_top10 ; CREATE TEMPORARY TABLE avg_top10 ( sch_code VARCHAR(4), schabbrev VARCHAR(75), totpct_stu DECIMAL(5,1) ); INSERT INTO avg_top10 SELECT sch_code , schabbrev , totpct_stu FROM test_table WHERE sch_code IN ('5489') ORDER BY totpct_stu DESC LIMIT 10;
Question: So this works, but there is no much better way to do this?
Thanks!
PS - It seems like homework, but this, well ... is real.
source share