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;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.