union的用法和@num:=在排名次的用法

错误
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:[email protected]+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:[email protected]+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:[email protected]+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:=在排名次的用法