Advertisement
bani30

Query Quotation Detail

Mar 3rd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. SELECT
  2. rfq.group AS group
  3. , rfq.currency AS currency
  4. , rfq.status AS status
  5. , SUM(CASE
  6. WHEN status = 'win' THEN total_tax
  7. WHEN status = 'lost' THEN total_tax
  8. WHEN status = 'on process' THEN total_tax
  9. END) AS value
  10. FROM
  11. (
  12. SELECT
  13. so.quotation_no AS "no"
  14. , so.create_date AS "date"
  15. , pp.name AS "currency"
  16. , gs.name AS "group"
  17. , so.amount_untaxed AS "total_tax"
  18. , CASE
  19. WHEN so.quotation_state NOT IN('win','lost') THEN 'on process'
  20. ELSE so.quotation_state
  21. END AS "status"
  22. FROM
  23. sale_order so
  24. LEFT JOIN product_pricelist pp ON pp.id = so.pricelist_id
  25. LEFT JOIN group_sales gs on gs.id = so.group_id
  26. WHERE gs.name = 'g1'
  27. ) AS rfq
  28. GROUP BY rfq.currency, rfq.group, rfq.status
  29. ORDER BY rfq.currency
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement