数据库表如下:
 id    typeName   chenji   addTime
  1      类型1      好     2009-6-1
  2      类型1      好     2009-8-9
  3      类型3      差     2009-4-9
  4      类型4      差     2009-11-9
  5      类型5     中等    2009-10-9
  6      类型6     中等    2009-9-9 我想在这个数据表中统计出 chenji 为 好 的个数、中等 的个数、差 的个数,并且可以 按 类型(typeName)、成绩(chenji)、添加时间来做查询
 各位高手能不能指点一下呢?感谢感谢啊,这个问题我考虑了很久了。

解决方案 »

  1.   

    select chenji, count(chenji)
    from table1
    group by chenji
      

  2.   

    select typeName, chenji, count(*)
    from table1
    group by typeName, chenji
      

  3.   

    这样不行,这样只是统计成绩(chenji)的总数,无法统计出成绩为好的,差好的啊
      

  4.   

    select name,count(case when chenji='好' then chenji end),
    count(case when chenji='差' then chenji end),
    count(case when chenji='中等' then chenji end),
    from table group by typeName   或group by addTime 
    没在数据库上面些,直接在这写的,你可以试下...
      

  5.   

    怎么不行? 前面不是还有chengji吗
    select chenji,count(chenji)from table1 where ... and ... group by chenji
      

  6.   

    1楼的是正确的。这样查询出来是    好   2
                                 差   2
                                 中等 2
    LZ在试试吧。怎么可能是chenji总数呢?
      

  7.   

    select typeName count(chenji)  addTime 
    from table group by chenji 
      

  8.   

    [Quote=引用 13 楼 laokaizzz 的回复:]
    6楼牛逼