so I have table Product_Information
| Product | Data type |
|---|---|
| Product_ID | NUMBER(6,0) |
| Warranty_Period | INTERVAL YEAR(2) TO MONTH |
How should I do a diapason check between intervals? This is the code I've tried
case W.WARRANTY_PERIOD
when INTERVAL '0-0' YEAR TO MONTH THEN 'No warranty'
when INTERVAL '0-3' YEAR TO MONTH THEN '3 months'
end as Warranty
I've already joined the table, but I need result like this:
| ProductID | Warranty Left |
|---|---|
| 102 | 1 year and 6 months |
| 103 | 4 months |
Use
EXTRACTin aCASEexpression:Which, for the sample data:
Outputs:
db<>fiddle here