日期:2014-05-17 浏览次数:20591 次
--参考:
SELECT a.*,b.*
FROM
(SELECT rowid=row_number() over(PARTITION BY ClassName order BY UserID), * from 学生信息表) a --楼主还可以把这行里的order by改成order by newid(),随机性更强
LEFT JOIN
(SELECT rowid=row_number() over(PARTITION BY ClassName order BY NEWID()), cnt=COUNT(1) OVER(PARTITION BY Classname), * FROM 试卷与班级分配结果表) b
ON a.ClassName = b.ClassName
AND a.rowid % cnt + 1 = b.rowid