1

我有以下 SQL 在此阶段效果很好:

  INSERT INTO recEntrantStatus (entrantId, roundId, judgeId, notified, voted, enterNextRound)
  SELECT entrantId, (@round + 1), judgeId, 0, 0, 0
  FROM recEntrantStatus
  WHERE roundId = @round
  AND voted = 1
  AND enterNextround = 1

此代码检查所有enterNextRound为 true 的行,然后为每个行创建一个新行。

但是,我现在需要扩展它,以便:

  1. 检查所有评委的第二个表 ( tblJudges) 并获取所有评委 ID (Id) 的数组

  2. 除了现在为从步骤 1 中获得的每个评委/评委 ID 创建上述每一行之外,与上述示例中的操作相同。

任何帮助/建议将一如既往地不胜感激。

谢谢!

4

1 回答 1

1

如果我对您的理解正确,这可能会有所帮助:

INSERT INTO recEntrantStatus (entrantId, roundId, judgeId, notified, voted, enterNextRound)
SELECT r.entrantId, (@round + 1), j.judgeId /*Now getting tblJudges Id*/, 0, 0, 0
FROM recEntrantStatus r
    -- Get all of the judges
    CROSS JOIN (SELECT DISTINCT Id AS judgeId FROM tblJudges) AS j
WHERE r.roundId = @round
    AND r.voted = 1 -- Is this based on a judge or an entrant status?
    AND r.enterNextround = 1

我们得到的结果和以前一样,只是乘以评委的数量,如果你愿意的话(并使用个人评委 ID)。

于 2012-10-10T17:46:54.517 回答