The code bellow is working but not giving me the correct results. Trying to correct the problem, I inserted MIN in the other WHEN lines of the CASE statment (with MIN("