错误 select Score.s_score,Course.c_name from Score left join Course on Score.c_id=Course.c_id where Course.c_id = '01' order by Score.s_score desc union all select Score.s_score,Course.c_name from Score left join Course on Score.c_id=Course.c_id where Course.c_id = '01' order by Score.s_score desc union select Score.s_score,Course.c_name from Score left join Course on Score.c_id=Course.c_id where Course.c_id = '01' order by Score.s_score desc 正确 select a.s_id,a.s_score,a.c_name,@num:=@num+1 from (select Score.*,Course.c_name from Score left join Course on Score.c_id=Course.c_id where Score.c_id = '01' ORDER BY Score.s_score ) a, (select @num:=0) num union select a.s_id,a.s_score,a.c_name,@num1:=@num1+1 from (select Score.*,Course.c_name from Score left join Course on Score.c_id=Course.c_id where Score.c_id = '02' ORDER BY Score.s_score ) a, (select @num1:=0) num1 union select a.s_id,a.s_score,a.c_name,@num2:=@num2+1 from (select Score.*,Course.c_name from Score left join Course on Score.c_id=Course.c_id where Score.c_id = '03' ORDER BY Score.s_score ) a, (select @num2:=0) num2
union的用法和@num:=在排名次的用法
最新推荐文章于 2023-02-15 13:56:56 发布