数据库表如下:
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)、添加时间来做查询
各位高手能不能指点一下呢?感谢感谢啊,这个问题我考虑了很久了。
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)、添加时间来做查询
各位高手能不能指点一下呢?感谢感谢啊,这个问题我考虑了很久了。
from table1
group by chenji
from table1
group by typeName, chenji
count(case when chenji='差' then chenji end),
count(case when chenji='中等' then chenji end),
from table group by typeName 或group by addTime
没在数据库上面些,直接在这写的,你可以试下...
select chenji,count(chenji)from table1 where ... and ... group by chenji
差 2
中等 2
LZ在试试吧。怎么可能是chenji总数呢?
from table group by chenji
6楼牛逼