A,B,C三个表,一共1000条数据,如何让其随机选择60条(平均分配A,B,C三表的数据)放在datagridview中
如题,在线等
------解决方案--------------------
SELECT * FROM (SELECT TOP 60 *, NewId() As RandomX FROM [A] Order By RandomX) AA
UNION ALL
SELECT * FROM (SELECT TOP 60 *, NewId() As RandomX FROM [B] Order By RandomX) BB
UNION ALL
SELECT * FROM (SELECT TOP 60 *, NewId() As RandomX FROM [C] Order By RandomX) CC
A,B,C字段名称必须相同
参见
http://dotnet.aspx.cc/file/Using-UNION-ALL-With-ORDER-BY-NEWID.aspx