Query runs for too long
Move the qnt &lt;= 0 inside as a HAVING (not WHERE).

Use JOIN ... ON ... instead of FROM a,b WHERE a...=b...

Add the following composite indexes:

a: INDEX(type, code, color)
b: INDEX(code, color, qnt)
c: INDEX(modello, commessa, stagione)