Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我的表名为sales. 它包含如下所示的列。
sales
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 天的平均销售量。 请帮我找出平均销售量
尝试
select avg(fld_count*fld_amount) as average from sales where fld_date > now() - interval 30 day
SQLFiddle 示例
你只会使用AVG()
AVG()
SELECT AVG(fld_amount * fld_count) AvgSales30 FROM sales WHERE fld_date > Date_Add(curdate(), interval -30 day)