Guest User

Untitled

a guest
Jan 17th, 2019
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.34 KB | None | 0 0
  1. (select 100 * ((SUM(time_product)/SUM(rt_id_count))*SUM(rental_cost))/SUM(sale_count) FROM
  2.  
  3. (select p2.id, p2.inventory_type, p2.working_value, COUNT(distinct p2.id),
  4.  
  5. ----nested values calculated here
  6. (case p2.inventory_type
  7. when 'set' then
  8. [calculation A]
  9. else [calculation B] end) rental_cost,
  10. (case p2.inventory_type
  11. when 'set' then
  12. [caluculation A]
  13. else [calculation B] end) sale_count,
  14. (case p2.inventory_type
  15. when 'set' then count(distinct rt.id)
  16. else 1 end
  17. ) rt_id_count,
  18. (case p2.inventory_type
  19. when 'set' then
  20. [calculation ] end) time_total,
  21. [calculation] time_product
  22.  
  23. FROM warehouses w
  24. LEFT JOIN rfid_tags rt ON w.id = rt.location_id AND rt.location_type = 'Warehouse'
  25. LEFT JOIN products p2 ON rt.ancestor_product_id = p2.id
  26. LEFT JOIN category_assignments ca ON ca.product_id = p2.id
  27. LEFT JOIN categories c ON ca.category_id = c.id
  28. LEFT JOIN product_selections ps ON ps.rfid_tag_id = rt.id
  29.  
  30. WHERE
  31. c.id=categories.id AND ca.primary = true AND w.id=warehouses.id
  32. AND (select count(ps.id) from product_selections ps where ps.rfid_tag_id=rt.id)>0
  33. and p2.working_value>0
  34. AND rt.location_id=w.id
  35. group by p2.id, p2.inventory_type, p2.working_value, c.sale_price_percentage, c.rental_price_percentage) Z) roi
Add Comment
Please, Sign In to add comment