MySQL Forums :: Newbie :: Group by
Re: Group by
Posted by: laptop alias ()
Date: March 27, 2012 11:35AM
To be honest, I don't really know why this works...
SET @prev = ''; SET @date = ''; SET @rank = 0; SELECT x.* , @prev := @date , @date := x.date , @rank := IF(@prev = @date, @rank, @rank+1) rank FROM ( SELECT intrunk , date , SUM(calldrop IN(16,31)) total FROM my_table GROUP BY date DESC, intrunk ) x HAVING rank <= 2;
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.