我可以 "GROUP BY" Access/SQL 中的部分字段值吗?

Can I "GROUP BY" a partial field value in Access/SQL?

在Access/SQL中,我知道我可以GROUP BY,比如说,countryage

我是否也可以 GROUP BY 部分值,例如,字段以 "G""18" 开头,这样 "Germany""Ghana" 是在一组中,"1897""1870"在一组中?

您可以将 MID()LEFT()GROUP BY 子句一起使用:

select mid(country,1,1), count(*)
from table t
group by mid(country,1,1); -- or with left (country,1)

您可以按任何非聚合表达式进行分组。例如:

SELECT   LEFT(country, 1), COUNT(*)
FROM     mytable
GROUP BY LEFT(country, 1)
select group_concat(country), count(*) as count
from employees
group by left(country,1)

我认为这应该可以解决

答案看起来像

India, Indonesia 2
America, Australia, Argentina 3