Sql (it) 开始 设置@counter=1 更新tbl_计数器设置计数器=1 结束 从Employees2中选择@Editor=Name,其中id=@counter 选择top 1 newid()作为unirow、t1.name编辑器、t2.name Contributor1、, t3.姓名出资人2、t4.姓名出资人3、t5.姓名出资人4 来自员工t1、员工t2、员工t3、员工t4、员工t5 其中t1.namet2.name和t1.namet3.name和t1.namet4.name和t1.namet5.name 和t2.namet1.name和t2.namet3.name和t2.namet4.name和t2.namet5.name 和t3.namet2.name和t3.namet1.name和t3.namet4.name和t3.namet5.name 和t4.namet2.name和t4.namet3.name和t4.namet1.name和t4.namet5.name 和t5.namet2.name和t5.namet3.name和t5.namet4.name和t5.namet1.name 和t1.name=@Editor unirow订购
结束首先,在给定约束的情况下,编辑器不是随机的。最初的顺序是随机的,但经过一个周期后,它永远不会改变。第二,编辑是否也可以为同一篇文章提供稿件?在所有10位用户都尝试过编辑之后,这个循环可能会重新开始;循环N的最后一个编辑器也可能是循环N+1的第一个编辑器。从“选择5,选择1作为编辑器,选择4作为贡献者”中可以明显看出,编辑器没有被指定为贡献者。是的,乔纳森,你是对的。我需要一个SQL查询来查询sameLooks。努力(+1)。我打赌我无法说服您使用PowershellpI真的应该跟上PowerShell的速度。。。有一天我不知道该如何感谢你…上帝保佑你和你的家人!这就是我的整个团队都在绞尽脑汁的解决方案如果你经过比利时,你可以请我喝一杯Sql (it) 开始 设置@counter=1 更新tbl_计数器设置计数器=1 结束 从Employees2中选择@Editor=Name,其中id=@counter 选择top 1 newid()作为unirow、t1.name编辑器、t2.name Contributor1、, t3.姓名出资人2、t4.姓名出资人3、t5.姓名出资人4 来自员工t1、员工t2、员工t3、员工t4、员工t5 其中t1.namet2.name和t1.namet3.name和t1.namet4.name和t1.namet5.name 和t2.namet1.name和t2.namet3.name和t2.namet4.name和t2.namet5.name 和t3.namet2.name和t3.namet1.name和t3.namet4.name和t3.namet5.name 和t4.namet2.name和t4.namet3.name和t4.namet1.name和t4.namet5.name 和t5.namet2.name和t5.namet3.name和t5.namet4.name和t5.namet1.name 和t1.name=@Editor unirow订购,sql,sql-server,sql-server-2005,Sql,Sql Server,Sql Server 2005,结束首先,在给定约束的情况下,编辑器不是随机的。最初的顺序是随机的,但经过一个周期后,它永远不会改变。第二,编辑是否也可以为同一篇文章提供稿件?在所有10位用户都尝试过编辑之后,这个循环可能会重新开始;循环N的最后一个编辑器也可能是循环N+1的第一个编辑器。从“选择5,选择1作为编辑器,选择4作为贡献者”中可以明显看出,编辑器没有被指定为贡献者。是的,乔纳森,你是对的。我需要一个SQL查询来查询sameLooks。努力(+1)。我打赌我无法说服您使用PowershellpI真的应该跟上Power
Editor Cont1 Cont2 Cont3 Cont4
20-Jun U1 U8 U9 U3 U4
21-Jun U7 U2 U5 U6 U10
22-Jun U3 U4 U9 U2 U8
23-Jun U4 U8 U3 U5 U2
and so on..
struct Team
{
string name;
int editorCount;
}
currentEditorList is a List of Team
existingUserList is a List of Team
currentEditorList = Get Current Editor List from DailyTeam
existingUserList = Get All Users from User and its editor count (may need left outer join)
todayTeam is a new Array
// populate the normal users to dailyTeam
while (todayTeam count is less than 4)
{
randomIndex = generate a random number (from 0 to 9)
userName = get name from existingUserNames[randomIndex]
if (userName is not in todayTeam)
{
add userName to todayTeam
}
}
sort existingUserList by its editorCount
editorName = get the first item from existingUserList
add editorName to todayTeam
SET NOCOUNT ON
DECLARE @Users TABLE (
UserName VARCHAR(3)
, EditorCount INTEGER
, ContributorCount INTEGER
)
DECLARE @Solutions TABLE (
ID INTEGER IDENTITY(1, 1)
, Editor VARCHAR(3)
, Contributor1 VARCHAR(3)
, Contributor2 VARCHAR(3)
, Contributor3 VARCHAR(3)
, Contributor4 VARCHAR(3)
)
DECLARE @Editor VARCHAR(3)
DECLARE @Contributor1 VARCHAR(3)
DECLARE @Contributor2 VARCHAR(3)
DECLARE @Contributor3 VARCHAR(3)
DECLARE @Contributor4 VARCHAR(3)
INSERT INTO @Users
SELECT 'U1', 0, 0
UNION ALL SELECT 'U2', 0, 0
UNION ALL SELECT 'U3', 0, 0
UNION ALL SELECT 'U4', 0, 0
UNION ALL SELECT 'U5', 0, 0
UNION ALL SELECT 'U6', 0, 0
UNION ALL SELECT 'U7', 0, 0
UNION ALL SELECT 'U8', 0, 0
UNION ALL SELECT 'U9', 0, 0
UNION ALL SELECT 'U0', 0, 0
/* Keep Generating combinations until at least one user has been editor for 10 times */
WHILE NOT EXISTS (SELECT * FROM @Solutions WHERE ID = 30)
BEGIN
SELECT TOP 1 @Editor = u.UserName
FROM @Users u
INNER JOIN (
SELECT EditorCount = MIN(EditorCount)
FROM @Users
) ec ON ec.EditorCount = u.EditorCount
ORDER BY NEWID()
UPDATE @Users SET EditorCount = EditorCount + 1 WHERE UserName = @Editor
INSERT INTO @Solutions VALUES (@Editor, NULL, NULL, NULL, NULL)
SELECT TOP 1 @Contributor1 = u.UserName
FROM @Users u
INNER JOIN (
SELECT ContributorCount = MIN(ContributorCount)
FROM @Users
) ec ON ec.ContributorCount = u.ContributorCount
WHERE UserName <> @Editor
ORDER BY NEWID()
UPDATE @Users SET ContributorCount = ContributorCount + 1 WHERE UserName = @Contributor1
UPDATE @Solutions SET Contributor1 = @Contributor1 WHERE Contributor1 IS NULL
SELECT TOP 1 @Contributor2 = u.UserName
FROM @Users u
INNER JOIN (
SELECT ContributorCount = MIN(ContributorCount)
FROM @Users
) ec ON ec.ContributorCount = u.ContributorCount
WHERE UserName NOT IN (@Editor, @Contributor1)
ORDER BY NEWID()
UPDATE @Users SET ContributorCount = ContributorCount + 1 WHERE UserName = @Contributor2
UPDATE @Solutions SET Contributor2 = @Contributor2 WHERE Contributor2 IS NULL
SELECT TOP 1 @Contributor3 = u.UserName
FROM @Users u
INNER JOIN (
SELECT ContributorCount = MIN(ContributorCount)
FROM @Users
) ec ON ec.ContributorCount = u.ContributorCount
WHERE UserName NOT IN (@Editor, @Contributor1, @Contributor2)
ORDER BY NEWID()
UPDATE @Users SET ContributorCount = ContributorCount + 1 WHERE UserName = @Contributor3
UPDATE @Solutions SET Contributor3 = @Contributor3 WHERE Contributor3 IS NULL
SELECT TOP 1 @Contributor4 = u.UserName
FROM @Users u
INNER JOIN (
SELECT ContributorCount = MIN(ContributorCount)
FROM @Users
) ec ON ec.ContributorCount = u.ContributorCount
WHERE UserName NOT IN (@Editor, @Contributor1, @Contributor2, @Contributor3)
ORDER BY NEWID()
UPDATE @Users SET ContributorCount = ContributorCount + 1 WHERE UserName = @Contributor4
UPDATE @Solutions SET Contributor4 = @Contributor4 WHERE Contributor4 IS NULL
END
SELECT * FROM @Solutions
SELECT * FROM @Users
DECLARE @counter number
DECLARE @limit number
DECLARE @Editor varchar(100)
select @limit=count(*) from Employees
select @counter=counter+1 from tbl_counter
IF(@counter>@limit)
begin
set @counter=1
update tbl_counter set counter=1
end
select @Editor=Name from Employees2 where id=@counter
select top 1 newid() as unirow,t1.name Editor,t2.name Contributor1,
t3.name Contributor2,t4.name Contributor3,t5.name Contributor4
from Employees t1,Employees t2,Employees t3,Employees t4,Employees t5
where t1.name<>t2.name and t1.name<>t3.name and t1.name<>t4.name and t1.name<>t5.name
and t2.name<>t1.name and t2.name<>t3.name and t2.name<>t4.name and t2.name<>t5.name
and t3.name<>t2.name and t3.name<>t1.name and t3.name<>t4.name and t3.name<>t5.name
and t4.name<>t2.name and t4.name<>t3.name and t4.name<>t1.name and t4.name<>t5.name
and t5.name<>t2.name and t5.name<>t3.name and t5.name<>t4.name and t5.name<>t1.name
and t1.name=@Editor
order by unirow