I have a couple of tables which have information about an activity(like an article), how do I get a column back that spits out a value based on some condition
Learner | Certificate view dt |
---|---|
First | 2023-10-09 |
Second | 2024-01-03 |
Learner | Certificate valid date |
---|---|
First | 2023-07-09 |
Second | 2024-02-23 |
For example I want to get some data through some comparisons(could be a different condition too) like
if(certificate view dt < certificate valid date) then return 'qualified' otherwise return 'unqualified'
ultimately I want to get something like this
Learner | Status |
---|---|
First | qualified |
Second | unqualified |
How to achieve that in sql or do I need something like a PL/SQL ?
2
Answers
With CASE
see online demo
output
The answer provided by @SimoneNigro is correct, except your data being split into two tables (I cannot see why you would do this but I’ll assume you have a valid reason). Since you have two tables it is necessary to consolidate them into single tuple for each
learner
. You use join to accomplish that. Resulting query becomes: (see demo here)NOTE: Demo adds learner Third to
certificate_view
but not tocertificate_valid
to show what happens with a missing row in one of the tables. Depending upon your data conditions the query may need corresponding adjustments.