SELECT accountrelation,itemrelation,quantity,amount
FROM ( SELECT accountrelation,itemrelation,quantity,amount,@rn := IF(@prev = itemrelation, @rn + 1, 1) AS rn,@prev := itemrelation
FROM mytable JOIN (SELECT @prev := NULL, @rn := 0) AS vars ORDER BY itemrelation, quantity DESC, accountrelation ) AS T1 WHERE rn <= 2