Fix sql errors in statistics part of component