Я пытаюсь сгенерировать комбинации каждой возможной команды, соответствующие правилам лиги. У меня есть два разных метода, к которым я подошел. Один из них - сделать все за один выбор.
Имейте в виду, что, вероятно, около 16 фунтов 32 фунта стерлингов 104 wrs 32 те 16 dst 16 k, а затем 168 fx. Через 10 часов я сгенерировал миллионы предметов, но он все еще не прошел полностью.
SELECT
QB.name, RB1.name, RB2.name, WR1.name, WR2.name, WR3.name, TE.name, FX.name, K.name, DST.name,
(QB.salary + RB1.salary + RB2.salary + WR1.salary + WR2.salary + WR3.salary + TE.salary + FX.salary + K.salary + DST.salary) AS cost,
(QB.projectedFloor + RB1.projectedFloor + RB2.projectedFloor + WR1.projectedFloor + WR2.projectedFloor + WR3.projectedFloor + TE.projectedFloor + FX.projectedFloor + K.projectedFloor + DST.projectedFloor) AS lowest,
(QB.projectedCeiling + RB1.projectedCeiling + RB2.projectedCeiling + WR1.projectedCeiling + WR2.projectedCeiling + WR3.projectedCeiling + TE.projectedCeiling + FX.projectedCeiling + K.projectedCeiling + DST.projectedCeiling) AS highest,
(QB.projectedPoints + RB1.projectedPoints + RB2.projectedPoints + WR1.projectedPoints + WR2.projectedPoints + WR3.projectedPoints + TE.projectedPoints + FX.projectedPoints + K.projectedPoints + DST.projectedPoints) AS projection
FROM quarterbacks QB
INNER JOIN defense DST
ON DST.defenseId = DST.defenseId
INNER JOIN kicker K
ON K.kickerId = K.kickerId
INNER JOIN tightends TE
ON TE.playersId = TE.playersId
INNER JOIN runningbacks RB1
ON RB1.playersId = RB1.playersId
INNER JOIN runningbacks RB2
ON RB2.playersId = RB2.playersId
INNER JOIN receivers WR1
ON WR1.playersId = WR1.playersId
INNER JOIN receivers WR2
ON WR2.playersId = WR2.playersId
INNER JOIN receivers WR3
ON WR3.playersId = WR3.playersId
INNER JOIN flex FX
ON FX.playersId = FX.playersId
WHERE
RB1.runningbacksId != RB2.runningbacksId AND
WR1.receiversId != WR2.receiversId AND
WR1.receiversId != WR3.receiversId AND
WR2.receiversId != WR3.receiversId AND
FX.playersId != RB1.playersId AND
FX.playersId != RB2.playersId AND
FX.playersId != WR1.playersId AND
FX.playersId != WR2.playersId AND
FX.playersId != WR3.playersId AND
FX.playersId != TE.playersId AND
(QB.salary + RB1.salary + RB2.salary + WR1.salary + WR2.salary + WR3.salary + TE.salary + K.salary + DST.salary) < 50000 AND
(QB.salary + RB1.salary + RB2.salary + WR1.salary + WR2.salary + WR3.salary + TE.salary + K.salary + DST.salary) > 45000
AND
(QB.projectedPoints + RB1.projectedPoints + RB2.projectedPoints + WR1.projectedPoints + WR2.projectedPoints + WR3.projectedPoints + TE.projectedPoints + FX.projectedPoints + K.projectedPoints + DST.projectedPoints) > 100
ORDER BY
(QB.projectedCeiling + RB1.projectedCeiling + RB2.projectedCeiling + WR1.projectedCeiling + WR2.projectedCeiling + WR3.projectedCeiling + TE.projectedCeiling + FX.projectedCeiling + K.projectedCeiling + DST.projectedCeiling),
(QB.projectedPoints + RB1.projectedPoints + RB2.projectedPoints + WR1.projectedPoints + WR2.projectedPoints + WR3.projectedPoints + TE.projectedPoints + FX.projectedPoints + K.projectedPoints + DST.projectedPoints),
(QB.projectedFloor + RB1.projectedFloor + RB2.projectedFloor + WR1.projectedFloor + WR2.projectedFloor + WR3.projectedFloor + TE.projectedFloor + FX.projectedFloor + K.projectedFloor + DST.projectedFloor)
У меня также есть другой подход, в котором я не совсем понимаю, будет ли он быстрее. Это включает в себя создание небольших таблиц, а затем их объединение.
DECLARE @QBSRBS TABLE (
qb nvarchar(max),
rb1 nvarchar (max),
rb2 nvarchar (max),
cost int,
highest float,
lowest float,
points float
);
DECLARE @WRS TABLE (
wr1 nvarchar(max),
wr2 nvarchar(max),
wr3 nvarchar(max),
cost int,
highest float,
lowest float,
points float
);
DECLARE @TEsDSTK TABLE (
te nvarchar(max),
fx nvarchar(max),
dst nvarchar(max),
k nvarchar(max),
cost int,
highest float,
lowest float,
points float
);
INSERT INTO @QBSRBS
SELECT
QB.name, RB1.name, RB2.name,
(QB.salary + RB1.salary + RB2.salary ) AS cost,
(QB.projectedFloor + RB1.projectedFloor + RB2.projectedFloor) AS lowest,
(QB.projectedCeiling + RB1.projectedCeiling + RB2.projectedCeiling) AS highest,
(QB.projectedPoints + RB1.projectedPoints + RB2.projectedPoints) AS projection
FROM quarterbacks QB
INNER JOIN runningbacks RB1
ON RB1.playersId = RB1.playersId
INNER JOIN runningbacks RB2
ON RB2.playersId = RB2.playersId
WHERE
RB1.runningbacksId != RB2.runningbacksId AND
RB1.team != RB2.team
INSERT INTO @WRS
SELECT
WR1.name, WR2.name, WR3.name,
(WR1.salary + WR2.salary + WR3.salary) AS cost,
(WR1.projectedFloor + WR2.projectedFloor + WR3.projectedFloor) AS lowest,
(WR1.projectedCeiling + WR2.projectedCeiling + WR3.projectedCeiling) AS highest,
(WR1.projectedPoints + WR2.projectedPoints + WR3.projectedPoints) AS projection
FROM receivers WR1
INNER JOIN receivers WR2
ON WR2.playersId = WR2.playersId
INNER JOIN receivers WR3
ON WR3.playersId = WR3.playersId
WHERE WR1.receiversId != WR2.receiversId AND
WR1.receiversId != WR3.receiversId AND
WR2.receiversId != WR3.receiversId AND
WR1.team != WR2.team AND WR1.team != WR3.team AND
WR2.team != WR3.team
INSERT INTO @TEsDSTK
SELECT TE.name, FX.name, K.name, DST.name,
(TE.salary + FX.salary + K.salary + DST.salary) AS cost,
(TE.projectedFloor + FX.projectedFloor + K.projectedFloor + DST.projectedFloor) AS lowest,
(TE.projectedCeiling + FX.projectedCeiling + K.projectedCeiling + DST.projectedCeiling) AS highest,
(TE.projectedPoints + FX.projectedPoints + K.projectedPoints + DST.projectedPoints) AS projection
FROM kicker K
INNER JOIN tightends TE
ON TE.playersId = TE.playersId
INNER JOIN flex FX
ON FX.playersId = FX.playersId
INNER JOIN defense DST
ON DST.defenseId = DST.defenseId
WHERE TE.playersId != FX.playersId
SELECT
qb, rb1, rb2, wr1, wr2, wr3, te, fx, k, dst,
(QR.cost + WR.cost + TFDK.cost) as cost,
(QR.lowest + WR.lowest + TFDK.lowest ) as lowest,
(QR.highest + WR.highest + TFDK.highest) as highest,
(QR.points + WR.points + TFDK.points) as points
FROM @QBSRBS QR
INNER JOIN @TEsDSTK TFDK
ON TFDK.cost = TFDK.cost
INNER JOIN @WRS WR
ON WR.cost = WR.cost
WHERE
QR.rb1 != TFDK.fx AND
QR.rb2 != TFDK.fx AND
WR.wr1 != TFDK.fx AND
WR.wr2 != TFDK.fx AND
WR.wr3 != TFDK.fx AND
(QR.highest + WR.highest + TFDK.highest) > 203
Как я могу повысить эффективность этого?