CREATE PROCEDURE [dbo].[schedule_duel_rank] AS BEGIN delete BattleRank -- 승점 전체 insert into BattleRank (rank_type, grade, character_id, char_name, char_class, duel_exp, total_win, total_lose) select top(100) 0, RANK() over(order by duel_exp desc), CT.character_id, CT.Name, CT.Class, BI.duel_exp, BI.total_win, BI.total_lose from BattleInfo BI with (nolock) inner join CharacterTable CT on CT.character_id = BI.character_id where BI.duel_exp > 100 -- 승점 프란츠 insert into BattleRank (rank_type, grade, character_id, char_name, char_class, duel_exp, total_win, total_lose) select top(100) 1, RANK() over(order by duel_exp desc), CT.character_id, CT.Name, CT.Class, BI.duel_exp, BI.total_win, BI.total_lose from BattleInfo BI with (nolock) inner join CharacterTable CT on CT.character_id = BI.character_id where BI.duel_exp > 100 and CT.Class = 1 or CT.Class = 101 or CT.Class = 102 -- 승점 안젤라 insert into BattleRank (rank_type, grade, character_id, char_name, char_class, duel_exp, total_win, total_lose) select top(100) 2, RANK() over(order by duel_exp desc), CT.character_id, CT.Name, CT.Class, BI.duel_exp, BI.total_win, BI.total_lose from BattleInfo BI with (nolock) inner join CharacterTable CT on CT.character_id = BI.character_id where BI.duel_exp > 100 and CT.Class =2 or CT.Class = 201 or CT.Class = 202 -- 승점 튜드 insert into BattleRank (rank_type, grade, character_id, char_name, char_class, duel_exp, total_win, total_lose) select top(100) 3, RANK() over(order by duel_exp desc), CT.character_id, CT.Name, CT.Class, BI.duel_exp, BI.total_win, BI.total_lose from BattleInfo BI with (nolock) inner join CharacterTable CT on CT.character_id = BI.character_id where BI.duel_exp > 100 and CT.Class = 3 or CT.Class = 301 or CT.Class = 302 -- 승점 나타샤 insert into BattleRank (rank_type, grade, character_id, char_name, char_class, duel_exp, total_win, total_lose) select top(100) 4, RANK() over(order by duel_exp desc), CT.character_id, CT.Name, CT.Class, BI.duel_exp, BI.total_win, BI.total_lose from BattleInfo BI with (nolock) inner join CharacterTable CT on CT.character_id = BI.character_id where BI.duel_exp > 100 and CT.Class = 4 or CT.Class = 401 or CT.Class = 402 -- 승점 Ladder insert into BattleRank (rank_type, grade, character_id, char_name, char_class, duel_exp, total_win, total_lose) select top(100) 100, RANK() over(order by duel_ladder_exp desc), CT.character_id, CT.Name, CT.Class, BI.duel_ladder_exp, BI.ladder_win, BI.ladder_lose from BattleInfo BI with (nolock) inner join CharacterTable CT on CT.character_id = BI.character_id where BI.duel_ladder_exp > 0 and BI.ladder_win + BI.ladder_lose > 0 delete from BattleRank where total_win + total_lose = 0 return 0 END