Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8019165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T21:18:15+00:00 2026-06-04T21:18:15+00:00

I have this little bit of code that I can’t quite work correctly. The

  • 0

I have this little bit of code that I can’t quite work correctly. The part giving me trouble is this:

IF( Class_Subset = @prevSub AND RegNum = @prevNum AND `DRI` >99.99 ,
@Platinum :=@Platinum + 1 ,''  )

What I need to do is tell the @Platinum to reset back to zero once the Class_Subset, or RegNum conditions are no longer met.

Any ideas?

Whole code:

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

This is what the file looks like, you can see why it needs to remember the variable while the RegNum and Subset match, but then reset to 0 once they change:

sample data http://nadacforum.com/Platinum.png

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T21:18:17+00:00Added an answer on June 4, 2026 at 9:18 pm

    I think I now see the issue.

    The row set where Platinum is being calculated is ordered by RegNum and Class_Subset (in particular), which is fine as the calculation does rely on those columns being sorted. But the IF() condition also involves the DRI column, and, as can be seen on your screenshot, a sequence of DRI values greater than 99.99 may be interrupted within a single group of (RegNum, Class_Subset). When it is reinstated, you need the Platinum values to carry on, not to reset to 1.

    Therefore, your @Platinum expression should be a bit more sophisticated. Here’s one way of changing it:

    @Platinum := IF (
     Class_Subset = @prevSub  
     AND RegNum = @prevNum  
     AND `DRI` > 99.99,
     @Platinum,  
     0
    ) + (`DRI` > 99.99) AS Platinum,  
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a little bit of code that looks just like this: function StrippedExample(i1,
its a little bit hard to understand. in the header.php i have this code:
I have a repeater of div's that look a little bit like this: <div
I have a jquery code, but I'm a little bit confused on how can
This question may seem a little bit stackoverflow-implementation specific, but I have seen a
I have this little problem, that I cannot figure out which arguments to pass
I have this little question that's been on my mind for a while now.
I have this little script that shows one wisdom each day. so I have
So I wrote this little bit of code to try out some new way
I have a bit of code that will open a Word 2007 (docx) document

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.