0

I need to show cash flow based on what we spent in the company.

We are selling various products day by day, and I have to show transactions in a better way.

Let's say that there is a data like this.

Date            Product        Profit
2012-08-17      Apple          $1.00
2012-08-17      Apple          $1.00
2012-08-17      Apple          $1.00
2012-08-16      Apple          $1.00
2012-08-16      Apple          $1.00
2012-08-14      Apple          $1.00
2012-08-13      Apple          $1.00
2012-08-13      Apple          $1.00
2012-08-13      Apple          $1.00

We sold 3 apples on Aug 17, and 2 apples on Aug 16. The one that I am trying to make a query helps to show below result.

Date            Product        Total Profit
2012-08-17      Apples         $3.00
2012-08-16      Apple          $2.00
2012-08-14      Apple          $1.00
2012-08-13      Apple          $3.00

I need to sum up all profit day by day.

Can you help me to make a query? I failed couple of times. Thank you.

4

3 回答 3

0

In the case that the product is the same you can use this query:

SELECT Date, Product, sum(Profit) as TotalProfit
FROM transactions
GROUP BY Date

In the case that the product is not the same you can use this query:

SELECT Date, Product, sum(Profit) as TotalProfit
FROM transactions
GROUP BY Product, Date
于 2012-11-17T08:51:52.537 回答
0

尝试这个

 select date,product,sum(profit) as totalprofit from table
 group by date,product
于 2012-11-17T08:44:13.327 回答
0
SELECT date,product,SUM(profit) FROM table
GROUP BY date
于 2012-11-17T08:45:21.600 回答