Skip to content
Advertisement

How to check whether a user has records in past?

Sample Table

Above sample table consists Users info who completed certifications. An user can also go for retraining but he/she should have completed a course before retaking it.

User Id: 2 is retrained on certificate 2, he has a record in past (Completed same certificate earlier), but User id: 3 has no certificates in past but he directly choose retraining.

How can we identify users who went for retraining without having a certification (Particular certificate) in past?

Ideally im looking for below structure for all retrainings?

Advertisement

Answer

You could just use LAG() to find out the previous record’s value.

If the previous record doesn’t exist, LAG() will return NULL by default.

So, the following code identifies three possibilities…

  1. Has never trained before
  2. Is re-training following a previous re-training
  3. Is re-training following a previous initial-training

User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement