Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/asp.net-core/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
MYSQL查询-将特定行的正值更改为负值。。。_Mysql_Mysql Workbench - Fatal编程技术网

MYSQL查询-将特定行的正值更改为负值。。。

MYSQL查询-将特定行的正值更改为负值。。。,mysql,mysql-workbench,Mysql,Mysql Workbench,我是mySQL查询新手 我有以下疑问: 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

我是mySQL查询新手

我有以下疑问:

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
返回以下数据:

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
我希望查询将num_secti 010更改为负值

预期成果:

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

直接减去扇区行数

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

这是可行的吗

您将使用
案例
语句:

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,
       . . .