Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I need to format in such way to get number of years, months and their combination or 'No warranty', depending on whether the given product has a warranty or not. I tried with case + extract but it didn't work
- select p.product_name, sum(o.quantity) as total_quantity,
- case when p.warranty_period = interval '0-0' year to month then 'No
- warranty'
- when p.warranty_period < interval '0-11' year to month then
- extract(month from p.warranty_period) || ' months'
- when p.warranty_period < interval '21-0' year to month then -- make it
- for all years, not only 1
- extract(year from p.warranty_period) || ' years'
- when p.warranty_period > interval '0-0' year to month then
- extract(year from p.warranty_period) || ' years and ' || extract(month
- from p.warranty_period)
- || ' months'
- end WARRANTY from PRODUCT_INFORMATION p
- join order_items o on p.product_id = o.product_id
- group by p.product_name, p.warranty_period;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement