按第一個字符分組: select count(*), left(name, 1)from the_tablegroup by left(name, 1); 如果id不是唯一的,您可能需要: select count(distinct id), left(name, 1)from the_tablegroup by left(name, 1); 更改范圍后編輯: 如果需要值之間的某種映射,請使用CASE表達式: select count(*), case when name in ('Bananas', 'Apples', 'Oranges') then 'Fruit' when name in ('Germany', 'France', 'Austria') then 'Country' else 'Something else' endfrom the_tablegroup by 2;