我有以下查询,当前返回 2 行(它总是只返回 2 行)。
Select
User_Profile.userid, User_Profile.displayname, User_Profile.picPath,
Battle.id as battleid, Battle.challenger_id as challengerid,
Video.[filename]
From
Battle
INNER Join
User_Profile ON Battle.challenger_id = User_Profile.userid OR
Battle.challenged_id = User_Profile.userid
INNER Join
Video ON User_Profile.userid = Video.[user_id]
WHERE
Video.battle_id = Battle.id
这将返回如下内容:
userid | displayname | picPath | battleid | challengerid | filename
--------------------------------------------------------------------
6 | CandyPoo | test.jpg | 12 | 9 | test.mp4
9 | Nawlrus | test2.jpg | 12 | 9 | test2.mp4
我希望返回这样的东西:
battleid | challengerid | xuserid | xdisplayname | xpicPath | xfilename | Yuserid | YdisplayName | YpicPath | YfileName
--------------------------------------------------------------------------------------------------------------------------
12 | 9 | 9 | Nawlrus | test2.jpg | test2.mp4 | 6 | CandyPoo | test.jpg | test.mp4
有没有办法做到这一点?我将返回多行,如上面的行(Top X),但需要合并具有相同battleid 的行,如您在上面看到的表格。这在 SQL Server 2008 中可行吗?