2

I want to get the value of the Total in pivot
for example

        | total_HT  | total_con | con(%)| 
-----------------------------------------
Total   |     1110  |      1010 |    200| 
-----------------------------------------
  Table |      100  |         0 |      0| 
 chaire |       10  |        10 |    100| 
desktop |     1000  |      1000 |    100| 

The value of con(%) 200 is not the value expected how can I get in the Total line the value 1010/1110= 91%

this is the query of on sale_report:

SELECT min(l.id) AS id
    ,l.product_id
    ,sum(l.price_total) AS total_ht
    ,sum(CASE 
            WHEN t.purchase_ok
                THEN l.price_total
            ELSE 0
            END) AS total_con
    ,sum(CASE 
            WHEN t.purchase_ok
                THEN l.price_total
            ELSE 0
            END) / sum(l.price_total)*100 AS con_percent
FROM sale_order_line l
INNER JOIN sale_order s ON l.order_id = s.id
LEFT JOIN product_product p ON l.product_id = p.id
LEFT JOIN product_template t ON p.product_tmpl_id = t.id
GROUP BY l.product_id
m3asmi
  • 1,252
  • 1
  • 16
  • 36

0 Answers0