Mysql
 sql >> Datenbank >  >> RDS >> Mysql

SQL - Summe einiger Zeilen minus Summe anderer Zeilen

select customer_code,
       sum(case
             when trans_type = 'DRINV' then
              trans_value
             else
              -trans_value
           end) as net_sales
  from dr_trans
 group by customer_code