Advertisement
Guest User

Untitled

a guest
Jun 25th, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. 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
  2.  
  3. select p.product_name, sum(o.quantity) as total_quantity,
  4.  
  5. case when p.warranty_period = interval '0-0' year to month then 'No
  6. warranty'
  7.  
  8. when p.warranty_period < interval '0-11' year to month then
  9. extract(month from p.warranty_period) || ' months'
  10.  
  11. when p.warranty_period < interval '21-0' year to month then -- make it
  12. for all years, not only 1
  13. extract(year from p.warranty_period) || ' years'
  14.  
  15. when p.warranty_period > interval '0-0' year to month then
  16. extract(year from p.warranty_period) || ' years and ' || extract(month
  17. from p.warranty_period)
  18. || ' months'
  19.  
  20. end WARRANTY from PRODUCT_INFORMATION p
  21. join order_items o on p.product_id = o.product_id
  22. group by p.product_name, p.warranty_period;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement