exec('CREATE VIEW task_internal_id AS SELECT COUNT(t1.id) internal_id, t1.id id, t1.project_id project_id FROM tasks t1 JOIN tasks t2 ON t1.id >= t2.id AND t1.project_id = t2.project_id GROUP BY t1.id, t1.project_id;'); }