-4

如何从一个表的前一行中减去(或添加)一行(stock_details)..并在另一个表中显示结果(item_details)..??

 1st table:stock_details
----------+----------+-----------
 stock_name | quantity | type  
------------+----------+----------
 laddu      |   200    | PURCHASE         
  Ghee      |    50    |  ISSUE        


2nd table:item_details
----------+----------
stock_name | quantity   
------------+---------
4

1 回答 1

0
-- INSERT INTO item_details
--  or
-- CREATE TABLE item_details
SELECT   stock_name, SUM(CASE type
           WHEN 'PURCHASE' THEN +quantity
           WHEN 'ISSUE'    THEN -quantity
         END) AS quantity
FROM     stock_details
GROUP BY stock_name
于 2013-05-19T09:04:36.637 回答