2013-12-17 93 views
-1

我需要幫助來選擇每月的數據數量,有4個零售商,我需要選擇每月的總交易量和該月的總額顯示每個月分別在SQL中。按月選擇數據

回答

2

從日期中提取月份並按組進行分組。然後你可以使用聚合函數來總結和計數

select month(date_column), 
     sum(amount) as total_amount, 
     count(*) as transaction_count 
from your_table 
group by month(date_column) 
select month(date_column), 
     sum(amount) as total_amount, 
     count(*) as transaction_count 
from your_table 
group by month(date_column) 
+0

嗨,謝謝你的幫助,但是當我使用月份時,count和sum不起作用,爲什麼? –

+0

對不起,我在腳本中犯了一個錯誤,它現在起作用 –