数据库的数据提取问题?
一个数据表中:
文化程度 姓名
高中 王
初中 李
大学 赵
…… ……
现在想将高中、初中、大学等各有多少人数统计出来,如何能方便快速的得到这些数据呢。
问题点数:100、回复次数:7Top
1 楼txmjs(天地之间)回复于 2003-11-01 21:03:09 得分 20
select count(文化程度) as gz from yourtable where 文化程度='高中'
select count(文化程度) as cz from yourtable where 文化程度='初中'
select count(文化程度) as dx from yourtable where 文化程度='大学'
Top
2 楼caohonglong2000(chl_csdn)回复于 2003-11-01 21:12:43 得分 10
select count(*) from table group by 文化程度 where 文化程度 ='高中';返回值就是要的统计数
同理可以统计其它人数:
select count(*) from table group by '文化程度' where 文化程度 ='初中';
select count(*) from table group by '文化程度' where 文化程度 ='大学';
Top
3 楼RockEx(石头)回复于 2003-11-01 21:47:20 得分 10
select 文化程度,sum(case 文化程度 when '高中' then '' end ) as '高中',
sum(case 文化程度 when '初中' then '' end ) as '初中',
sum(case 文化程度 when '大学' then '' end ) as '大学'
from 表名 group by 文化程度
得到
初中,高中,大学
10 10 10
Top
4 楼niat97222(Freeman)回复于 2003-11-01 21:56:09 得分 10
select 文化程度,count(*) from 表名 group by 文化程度Top
5 楼pengdali()回复于 2003-11-02 00:01:33 得分 10
select 文化程度,count(*) 人数 from 你的表 group by 文化程度Top
6 楼pengdali()回复于 2003-11-02 00:02:41 得分 10
如果还有其他的记录:
select 文化程度,count(*) 人数 from 你的表 where 文化程度 in('高中','初中','大学') group by 文化程度Top
7 楼sixgj(轰炸机)回复于 2003-11-04 20:15:09 得分 30
select count(*) from table where 文化程度 ='高中';
select count(*) from table where 文化程度 ='初中';
select count(*) from table where 文化程度 ='大学';Top




