mysql统计一列中有多少不同的值

2025年03月23日 06:53
有2个网友回答
网友(1):

select count(*) from (select distinct 列名 from 表名) a

网友(2):

用group by    例如

select count(id) from stu group by age

查学生表,按age分组,计算出id的数量 , 得出就是所有不同值年龄的数量