Select query taking too long MYSQL 5.6.17
You could try doing your Case selects as a cte. 
The  line: A.'stagione' IN (SELECT DISTINCT STAGIONE FROM wb_mod_deposit_out WHERE CREATED BETWEEN '2017-12-11' AND '2017-12-17')


will also be a memory hog. Do you have an index on your CREATED column?


Also, if you can find a way to take out TRIM(LEADING '0' FROM a.'commessa') = TRIM(LEADING '0' FROM c.'commessa') - maybe do it in an update statement or a third cte.