4 ms·
For example: if you have a coupon that has a start and end time (but the end time is optional), typically, you'd have a start_at and end_at datetime columns. Th
by joevandyk 14y ago
For example: if you have a coupon that has a start and end time (but the end time is optional), typically, you'd have a start_at and end_at datetime columns. The query for checking for an active coupon would be:
select * from coupons
where start_at < now() and (end_at is null or end_at > now())
Now, you can have a single column that represents the range of time that the coupon is active.
select * from coupons where now() <@ duration;
Plus, exclusion contraints. So you could prevent the database from storing a coupon that was active at the same time as another coupon.