All right. As we mentioned previously, you can use various conditions in a single
CASE WHEN clause. As usual, here comes an example:
WHEN pay_date < '2015-06-01' THEN 'database error'
WHEN pay_date BETWEEN '2015-06-01'
AND '2015-06-05' THEN 'accepted'
WHEN pay_date = '2015-06-06'
THEN 'conditionally accepted'
ELSE 'not accepted'
END AS payment_status
The situation is as follows: each candidate was supposed to pay an application fee between June 1 and June 5. If the system provides an earlier date, this must be clearly a mistake, because the bank account was only opened on June 1 (hence the status 'database error'). Those who indeed paid between June 1 and June 5 got a status 'accepted'. The university also agreed to accept those who paid a day later ('conditionally accepted'). There was, however, no mercy for those who paid even later – they did not qualify. Poor them.
Note that we could use the less than sign, the
BETWEEN construction and the equality sign (
=) - all in a single
CASE clause. In other words, you can basically use all the operators and functions you've learned so far. This is the magic of searched