Question

I'm new in mySQL queries...

I have below query :

SELECT 
    DISTINCT gp_style_gr.code_groupe, po_lot.num_style, po_lot_sp.Num_lot, 
    po_lot_sp.num_secti, po_lot_se.code_secti, po_lot.terminer, 
    po_lot.date_livraison, po_lot_sp.qte_1, po_lot_sp.qte_2, 
    po_lot_sp.qte_3, po_lot_sp.qte_4, po_lot_sp.qte_5, 
    po_lot_sp.qte_6, po_lot_sp.qte_7, po_lot_sp.qte_8, 
    po_lot_sp.qte_9, po_lot_sp.qte_10, po_lot_sp.qte_11, 
    po_lot_sp.qte_12, po_lot_sp.qte_13, po_lot_sp.qte_14, 
    po_lot_sp.qte_15, po_lot_sp.qte_16, po_lot_sp.qte_17, 
    po_lot_sp.qte_18, po_lot_sp.qte_19, po_lot_sp.qte_20, 
    po_lot_sp.qte_21, po_lot_sp.qte_22, po_lot_sp.qte_23, 
    po_lot_sp.qte_24, po_lot_sp.qte_25, po_lot_sp.qte_26, 
    po_lot_sp.qte_27, po_lot_sp.qte_28, po_lot_sp.qte_29, 
    po_lot_sp.qte_30

FROM po_lot_sp

LEFT OUTER JOIN po_lot_se 
    ON po_lot_se.num_lot = po_lot_sp.num_lot 
        and po_lot_se.num_secti = po_lot_sp.num_secti

LEFT OUTER JOIN po_lot 
    ON po_lot.num_lot = po_lot_sp.num_lot
LEFT OUTER JOIN gp_style_gr 
    ON gp_style_gr.num_style = po_lot.num_style

WHERE
((gp_style_gr.code_groupe = 'INSTOCK') and (po_lot.terminer = '0') 
    and (po_lot_se.code_secti = '01')) or 
    ((gp_style_gr.code_groupe = 'INSTOCK') and (po_lot.terminer = '0') 
    and (po_lot_se.code_secti = '09'))

ORDER BY gp_style_gr.code_groupe, po_lot.num_style, po_lot_sp.Num_lot, 
    po_lot_sp.num_secti, po_lot_se.code_secti, po_lot.terminer, 
    po_lot.date_livraison, po_lot_sp.qte_1, po_lot_sp.qte_2, 
    po_lot_sp.qte_3, po_lot_sp.qte_4, po_lot_sp.qte_5, 
    po_lot_sp.qte_6, po_lot_sp.qte_7, po_lot_sp.qte_8, 
    po_lot_sp.qte_9, po_lot_sp.qte_10, po_lot_sp.qte_11, 
    po_lot_sp.qte_12, po_lot_sp.qte_13, po_lot_sp.qte_14, 
    po_lot_sp.qte_15, po_lot_sp.qte_16, po_lot_sp.qte_17, 
    po_lot_sp.qte_18, po_lot_sp.qte_19, po_lot_sp.qte_20, 
    po_lot_sp.qte_21, po_lot_sp.qte_22, po_lot_sp.qte_23, 
    po_lot_sp.qte_24, po_lot_sp.qte_25, po_lot_sp.qte_26, 
    po_lot_sp.qte_27, po_lot_sp.qte_28, po_lot_sp.qte_29, 
    po_lot_sp.qte_30

Returning below data:

code_groupe num_style   Num_lot num_secti   code_secti  
    terminer    date_livraison  qte_1   qte_2   
INSTOCK ACROBAT D2954   001 01  0   2014-04-04  5   10  
INSTOCK ACROBAT D2954   010 09  0   2014-04-04  1   8   
INSTOCK ACROBAT D2999   001 01  0   2014-04-04  30  90  
INSTOCK ACROBAT D2999   010 09  0   2014-04-04  15  70

I would like the query to change the num_secti 010 to a negative value...

Expected results:

code_groupe num_style   Num_lot num_secti   code_secti  
    terminer    date_livraison  qte_1   qte_2   
INSTOCK ACROBAT D2954   001 01  0   2014-04-04  5   10  
INSTOCK ACROBAT D2954   010 09  0   2014-04-04  -1  -8  
INSTOCK ACROBAT D2999   001 01  0   2014-04-04  30  90  
INSTOCK ACROBAT D2999   010 09  0   2014-04-04  -15 -70

OR

directly subtract num_secti rows...

code_groupe num_style   Num_lot num_secti   code_secti  
    terminer    date_livraison  qte_1   qte_2   
INSTOCK ACROBAT D2954   001 01  0   2014-04-04  4   2       
INSTOCK ACROBAT D2999   001 01  0   2014-04-04  15  20

is it something feasible?

No correct solution

OTHER TIPS

You would use a case statement:

select . . .
       (case when num_secti = '010' then - po_lot_sp.qte_1 else po_lot_sp.qte_1 end) as qte_1,
       (case when num_secti = '010' then - po_lot_sp.qte_2 else po_lot_sp.qte_2 end) as qte_2,
       . . . 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top