读书人

group by 和count,该如何处理

发布时间: 2012-05-08 22:09:41 作者: rapoo

group by 和count
select count(type) from product group by type
结果统计出来的是每组的个数(多行结果)
想统计有多少种类型(单一结果)要怎么写?
除了这种写法,单一语句能完成吗?
select count(1) from (select count(type) from product group by type)

[解决办法]
select count(distinct type) from product
[解决办法]

探讨

select count(distinct type) from product

读书人网 >Mysql

热点推荐