我有一点代码,我不能完全正常工作。给我带来麻烦的部分是:
IF( Class_Subset = @prevSub AND RegNum = @prevNum AND `DRI` >99.99 ,
@Platinum :=@Platinum + 1 ,'' )
我需要做的是告诉, 或条件不再满足时@Platinum
重置回。zero
Class_Subset
RegNum
有任何想法吗?
整个代码:
SELECT
Harley.Hgt, Harley.RegNum, Harley.Callname, Harley.OLastname,
Harley.Tpe, Harley.Points, Harley.Class, Harley.Total_Points,
Harley.Title, Harley.Platinum, Harley.Silver_Purple,
Harley.Date_Earned, Harley.Judge, Harley.HostClub, Harley.DRI,
Harley.Class_Subset, Harley.IncorrectRegNum, Harley.MemNum, Harley.ID
FROM
(
SELECT
Hgt, RegNum, Callname, OLastname, Tpe, Points, Class,
Total_Points, Title, Silver_Purple, Date_Earned, Judge,
HostClub, DRI, Class_Subset, IncorrectRegNum, MemNum, ID,
IF (
Class_Subset = @prevSub
AND RegNum = @prevNum
AND `DRI` > 99.99,
@Platinum := @Platinum + 1,
0
) AS Platinum,
@prevSub := Class_Subset,
@prevNum := RegNum
FROM
Harley,
(
SELECT @Platinum := 0, @prevSub := '', @prevNum := ''
) r
ORDER BY RegNum, Class_Subset, Date_Earned
) Harley
这就是文件的样子,您可以看到为什么它需要在 RegNum 和 Subset 匹配时记住变量,但一旦它们发生变化就会重置为 0: