Are you using MySQL?
OK, if you are then first simplify your query:
select date_format(dt_imp,'%Y/%m') as date,
SUM(imp)
from sp
group by 1
order by 1
Then add the AVG column which will work ok with the "group by" :
select date_format(dt_imp,'%Y/%m') as date,
SUM(imp),
AVG(imp)
from sp
group by 1
order by 1
Is this what you were after? (if not, let me know and I'll try again..)
Cheers,
Andrew
-----Original Message-----
From: getting_out [mailto:[EMAIL PROTECTED]
Sent: Monday 08 December 2003 17:21
To: MySQL ML
Subject: Avarage monthly import
Hello people.
I have a table structured like this
+----------+-----------------------+
| Field | Type |
+----------+-----------------------+
| dt_imp | date |
| imp | decimal(5,2) |
+----------+-----------------------+
If I want to get the total per month I can do a query like this
select date_format(a.dt_imp,'%Y/%m') "date",
SUM(a.imp)
from sp a
group by date_format(a.dt_imp, '%Y/%m')
order by 1
with a result like this
+---------+----------------+
| ... | ... |
| 2002/02 | 238.30 |
| 2002/03 | 1385.95 |
| 2002/04 | 475.30 |
| 2002/05 | 171.10 |
| ... | ... |
+---------+----------------+
now, I would like to get the avarage monthly import, so I could use the
AVG() function.
Unfortunly I didn't understand how to use it in my case.
I've tried something like
select avg(subqry1) from sp
or
select * from subqry1
where suqry1 is the query precedently written; but I didn't succed in this.
How can I do to solve my problem?
thanks everybody.
G.
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]
--
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]