I\'m quite bad with SQL, I\'m using MYSQL and node and I run every 5 mins this queries:
UPDATE bolletta set status = (CASE WHEN (SELECT SUM(ticke