added subgroup ascending sorting in output from db