2012-11-17 93 views
0

我需要根據公司花費顯示現金流量。MySQL查詢 - 根據日期顯示數據

我們每天都在銷售各種產品,而且我必須以更好的方式展示交易。

假設有這樣的數據。

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 

我們賣掉08月17 3個蘋果和2個蘋果上月16 的一個,我想做一個查詢有助於顯示下面的結果。

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 

我需要總結所有的利潤日復一日。

你能幫我查詢嗎?我幾次都失敗了。謝謝。

回答

0

試試這個

select date,product,sum(profit) as totalprofit from table 
group by date,product 
0
SELECT date,product,SUM(profit) FROM table 
GROUP BY date 
0

在這種情況下,該產品是一樣的,你可以使用此查詢:

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

在這種情況下,該產品是不一樣的,你可以使用此查詢:

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