似乎和我之前的一个查询差不多.不过看起来我这个写的复杂了一些.
我是从一个表中(ppgameuser)查出每个游戏的最高得分者.
CREATE PROCEDURE spOrderAllGame
AS
begin
SELECT * INTO #mytbl FROM ppgameuser p,games g WHERE p.GamesID = g.gameid
SELECT gamesid, MAX(source) AS max_cost
INTO #mytemp
FROM ppgameuser
GROUP BY gamesid
HAVING (COUNT(*) > 1)
DELETE #mytbl FROM #mytemp, #mytbl WHERE #mytbl.GamesID = #mytemp.GamesID AND #mytbl.source <> #mytemp.max_cost
select top 10 u.username as UNM,GameID,GameName from #mytbl t,users u WHERE t.username = u.username ORDER BY GamesID DESC
end
GO