some sql request fixes and optimization
add generateTeamNMatch function (not tested)