比如下面一个表
id      name      type
1       asdsd       a
2       asdsd       b
3       asdsd       a
4       asdsd       c
5       asdsd       c
6       asdsd       a
7       asdsd       b
8       asdsd       a
9       asdsd       a我想得到的统计结果是按照type分类,从表中可以看出,结果是a为5条记录,b为2条记录,c为2条记录,怎样写出相对应的SQL语句?

解决方案 »

  1.   


      select type,count(1) from table 
      group by type
      

  2.   

    上面的同学,count里面的1是什么意思啊?
      

  3.   

    count(1)是简写的。可以写count(type) count(id)等等
      

  4.   

    count(1)这样统计每个type的记录条数
      

  5.   

    count(1)=count(*)  所有记录
      

  6.   

     select type,count(type) from table 
      group by type
    你就把他当做 type 有多少条  好看懂
    type  改成 数字多少都可以,也可以写成  表中 任何字段名  
    都行的    只是统计数量用的,就是不能写成表中没有字段的  英文名