MySQL Forums
Forum List  »  Newbie

Re: aggreate data
Posted by: Rick James
Date: September 26, 2010 10:28PM

You cannot do
select *, max(used) as maxused, avg(used) as avgused from space where mountpoint='/' group by date with rollup;
in a single step -- the '*' will come from the 'first' row encountered (likely to be the earliest time).

This will work, yes?
select max(used) as maxused, avg(used) as avgused from space where mountpoint='/' group by date with rollup;

select *
    FROM (
        SELECT *
            from space
            where mountpoint='/'
            ORDER BY used DESC
          ) x       -- First do the ORDERing
    GROUP BY date   -- Then pick the one row per day desired
Does that get the '*' and (effectively) the maxused?

Then you wanted two more things; here's one of them:
select  *,
        ( SELECT avg(used) FROM space WHERE date = x.date ) AS avgused 
    FROM ( ... ) x
    GROUP BY date

Options: ReplyQuote


Subject
Written By
Posted
September 26, 2010 09:47PM
September 26, 2010 09:54PM
September 26, 2010 10:02PM
Re: aggreate data
September 26, 2010 10:28PM
September 27, 2010 05:48AM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.