How to SUM and SUBTRACT using SQL?

前端 未结 6 1451
甜味超标
甜味超标 2020-12-09 08:09

I am using MySQL and I have two tables:

master_table

  • ORDERNO
  • ITEM
  • QTY

stock_bal

6条回答
  •  难免孤独
    2020-12-09 08:42

    I'm not sure exactly what you want, but I think it's along the lines of:

    SELECT `Item`, `qty`-`BAL_QTY` as `qty` FROM ((SELECT Item, SUM(`QTY`) as qty FROM `master_table` GROUP BY `ITEM`) as A NATURAL JOIN `stock_table`) as B
    

提交回复
热议问题