这个问题 急!急!急!急!急!急!急!急!一个数据库查询的问题

xulili123 2009-11-30 09:20:52
数据库表如下:
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)、添加时间来做查询
各位高手能不能指点一下呢?感谢感谢啊,这个问题我考虑了很久了。
...全文
141 16 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
16 条回复
切换为时间正序
请发表友善的回复…
发表回复
hhwangke 2009-12-12
  • 打赏
  • 举报
回复
6楼的方法很好。
zuoming120 2009-11-30
  • 打赏
  • 举报
回复
hyl200255 2009-11-30
  • 打赏
  • 举报
回复
[Quote=引用 13 楼 laokaizzz 的回复:]
6楼牛逼
laokaizzz 2009-11-30
  • 打赏
  • 举报
回复
6楼牛逼
xfl_001 2009-11-30
  • 打赏
  • 举报
回复
[Quote=引用 6 楼 java_caicai 的回复:]
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


没在数据库上面些,直接在这写的,你可以试下...
[/Quote]

你这种方法是可以的,真太谢谢你了啊,哈哈!
xfl_001 2009-11-30
  • 打赏
  • 举报
回复
[Quote=引用 8 楼 ljs0203 的回复:]
引用 3 楼 xulili123 的回复:
引用 1 楼 wuyi8808 的回复:
SQL code
select chenji,count(chenji)from table1groupby chenji

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



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

我的意思是 把它们 分别取出来 赋给 变量 ,我是这样意思 ,呵呵
xfl_001 2009-11-30
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 kaukiyou 的回复:]
引用 3 楼 xulili123 的回复:
引用 1 楼 wuyi8808 的回复:
SQL codeselect chenji,count(chenji)from table1 groupby chenji

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

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

这样选的话只会把 成绩好 成绩差 会都选出来,我要的是分别 把它们选 出来
war_zhong 2009-11-30
  • 打赏
  • 举报
回复
select typeName count(chenji) addTime
from table group by chenji
ljs0203 2009-11-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xulili123 的回复:]
引用 1 楼 wuyi8808 的回复:
SQL code
select chenji,count(chenji)from table1groupby chenji

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


1楼的是正确的。这样查询出来是 好 2
差 2
中等 2
LZ在试试吧。怎么可能是chenji总数呢?
kaukiyou 2009-11-30
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 xulili123 的回复:]
引用 1 楼 wuyi8808 的回复:
SQL codeselect chenji,count(chenji)from table1 groupby chenji

这样不行,这样只是统计成绩(chenji)的总数,无法统计出成绩为好的,差好的啊
[/Quote]
怎么不行? 前面不是还有chengji吗
select chenji,count(chenji)from table1 where ... and ... group by chenji
java_caicai 2009-11-30
  • 打赏
  • 举报
回复
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


没在数据库上面些,直接在这写的,你可以试下...
limii 2009-11-30
  • 打赏
  • 举报
回复
up
xfl_001 2009-11-30
  • 打赏
  • 举报
回复
自己顶起来!
xulili123 2009-11-30
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 wuyi8808 的回复:]
SQL codeselect chenji,count(chenji)from table1groupby chenji
[/Quote]
这样不行,这样只是统计成绩(chenji)的总数,无法统计出成绩为好的,差好的啊
wuyi8808 2009-11-30
  • 打赏
  • 举报
回复
select typeName, chenji, count(*)
from table1
group by typeName, chenji
wuyi8808 2009-11-30
  • 打赏
  • 举报
回复
select chenji, count(chenji)
from table1
group by chenji

62,248

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术交流专区
javascript云原生 企业社区
社区管理员
  • ASP.NET
  • .Net开发者社区
  • R小R
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

.NET 社区是一个围绕开源 .NET 的开放、热情、创新、包容的技术社区。社区致力于为广大 .NET 爱好者提供一个良好的知识共享、协同互助的 .NET 技术交流环境。我们尊重不同意见,支持健康理性的辩论和互动,反对歧视和攻击。

希望和大家一起共同营造一个活跃、友好的社区氛围。

试试用AI创作助手写篇文章吧