How to separate a record to get the amount

后端 未结 2 1454
刺人心
刺人心 2021-02-11 09:50

I got total 160 Quantity in the Stock.

How to get first 100 quantity total amount and last 60 quantity total amount?

The table is sort by Date and Stock ID.

2条回答
  •  广开言路
    2021-02-11 10:28

    For first 100

    select Product ID, sum(Quantity) as Quantity, sum(Amount) as TotalAmount from (SELECT * from tblstock order by tblStock.Stock ID ASC limit 100) t1 GROUP BY Date,Product ID

    For last 60

    select Product ID, sum(Quantity) as Quantity, sum(Amount) as Total Amount from (SELECT * from tblstock order by tblStock.Stock ID DESC limit 60) t1 GROUP BY Date,Product ID

提交回复
热议问题