Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- rfq.group AS group
- , rfq.currency AS currency
- , rfq.status AS status
- , SUM(CASE
- WHEN status = 'win' THEN total_tax
- WHEN status = 'lost' THEN total_tax
- WHEN status = 'on process' THEN total_tax
- END) AS value
- FROM
- (
- SELECT
- so.quotation_no AS "no"
- , so.create_date AS "date"
- , pp.name AS "currency"
- , gs.name AS "group"
- , so.amount_untaxed AS "total_tax"
- , CASE
- WHEN so.quotation_state NOT IN('win','lost') THEN 'on process'
- ELSE so.quotation_state
- END AS "status"
- FROM
- sale_order so
- LEFT JOIN product_pricelist pp ON pp.id = so.pricelist_id
- LEFT JOIN group_sales gs on gs.id = so.group_id
- WHERE gs.name = 'g1'
- ) AS rfq
- GROUP BY rfq.currency, rfq.group, rfq.status
- ORDER BY rfq.currency
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement