Fix : sql query for calculate used resources for a perdio