Pregunta

My table named as sales. It contains the column like the following.

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),

I want to find out the avg of last 30 days sale.
pls help me to find the average of sale

¿Fue útil?

Solución

You will just use AVG()

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

Otros consejos

try

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

SQLFiddle example

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top