Query OK, 0 rows affected (0.02 sec)
obclient> CREATE TABLE t_case2(id number NOT NULL PRIMARY KEY, c_date date );
Query OK, 0 rows affected (0.14 sec)
obclient> INSERT INTO t_case2(id,c_date)
VALUES (1,'2019-03-01')
,(2,'2019-05-08')
,(3,'2019-07-07')
,(4,'2019-10-11')
Query OK, 6 rows affected (0.01 sec)
Records: 6 Duplicates: 0 Warnings: 0
obclient>
obclient> SELECT id, c_date,
CASE
WHEN datediff(now(), c_date) > 12*30 THEN 'More than one year ago'
WHEN datediff(now(), c_date) > 9*30 THEN 'More than three quarters ago'
WHEN datediff(now(), c_date) > 6*30 THEN 'More than half a year ago'
WHEN datediff(now(), c_date) > 3*30 THEN 'More than a quarter ago'
WHEN datediff(now(), c_date) >= 0 THEN 'Within a quarter'
END "Duration"
FROM t_case2;
+----+------------+------------------------------+
| id | c_date | Duration |
+----+------------+------------------------------+
| 1 | 2019-03-01 | More than one year ago |
| 2 | 2019-05-08 | More than three quarters ago |
| 3 | 2019-07-07 | More than three quarters ago |
| 4 | 2019-10-11 | More than a quarter ago |
| 5 | 2019-12-12 | More than a quarter ago |
| 6 | 2020-01-05 | Within a quarter |