2012-08-29 65 views
0

我的表名爲sales。它包含如下所示的列。關於mysql中days函數的查詢

fld_id int(11), 
fld_date date, 
fld_state varchar(45), 
fld_dtcode varchar(45), 
fld_companyname varchar(150), 
fld_unitrate int(11), 
fld_count int(11), 
fld_amount int(11), 

我想知道最近30天銷售的平均值。
請幫助我找到銷售的平均

回答

1

你只使用AVG()

SELECT AVG(fld_amount * fld_count) AvgSales30 
FROM sales 
WHERE fld_date > Date_Add(curdate(), interval -30 day) 
1

嘗試

select avg(fld_count*fld_amount) as average 
from sales 
where fld_date > now() - interval 30 day 

SQLFiddle example