ITPUB??ì3
12月微软Hyper-V虚拟化沙龙主题征集
ITPUB论坛 » MS SQL Server » 跪求一条SQL语句

标题: [原创] 跪求一条SQL语句
离线 gpro



精华贴数 0
个人空间 0
技术积分 18 (61624)
社区积分 0 (1764286)
注册日期 2008-4-22
论坛徽章:0
      
      

发表于 2008-9-12 07:55 
跪求一条SQL语句

某学校人事资料表employee里面有有一个关于文化程度的栏住字段WH,里面有本科以上,大专以上,高中,初中文凭,现在要用一条SQL语句查出各文化水平的人员数量和各文化水平的人员数量占总人员数量的百分比。

谢谢大家!!!


只看该作者    顶部
离线 潇洒老乌龟
十八年风雨,守得冰山雪莲花开



精华贴数 0
个人空间 0
技术积分 516 (3814)
社区积分 0 (580927)
注册日期 2005-8-25
论坛徽章:0
      
      

发表于 2008-9-12 10:26 
select wh , m.cnt*100.0/(select count(1) from employee) bfb from
(select WH , count(*) cnt from employee group by wh) m


__________________
十八年风雨,守得冰山雪莲花开
只看该作者    顶部
离线 苏宁No.1
5.12 生者何哀 死者何苦


精华贴数 6
个人空间 0
技术积分 1081 (1704)
社区积分 28124 (38)
注册日期 2004-3-30
论坛徽章:28
ITPUB元老生肖徽章2007版:虎生肖徽章2007版:龙   
      

发表于 2008-9-12 10:32 


create table temp_david(wh varchar2(100))
insert into temp_david values('大學')
insert into temp_david values('大學')
insert into temp_david values('大學')
insert into temp_david values('大專')
insert into temp_david values('大專')
insert into temp_david values('高中')
insert into temp_david values('高中')
insert into temp_david values('初中')
insert into temp_david values('初中')
insert into temp_david values('初中')

select count(*) all_count,
sum(case when wh ='大學' then 1 else 0 end) as "大學",
round(sum(case when wh ='大學' then 1 else 0 end)/count(*),3)*100||'%' as "大學比例",
sum(case when wh ='大專' then 1 else 0 end) as "大專",
round(sum(case when wh ='大專' then 1 else 0 end)/count(*),3)*100||'%' as "大專比例",
sum(case when wh ='高中' then 1 else 0 end) as "高中",
round(sum(case when wh ='高中' then 1 else 0 end)/count(*),3)*100||'%' as "高中比例",
sum(case when wh ='初中' then 1 else 0 end) as "初中",
round(sum(case when wh ='初中' then 1 else 0 end)/count(*),3)*100||'%' as "初中比例"
from temp_david




__________________
MSN:suning77088@hotmail.com Mail/Gtalk:suning77088@gmail.com QQ:306831613  我的淘宝小店:运动A元素
法律咨詢QQ群:33968809

5.12 永志不忘
有中国特色的奴隶主义社会

打算做个网站
只看该作者    顶部
 
    

相关内容


CopyRight 1999-2006 itpub.net All Right Reserved.
北京皓辰广域网络信息技术有限公司. 版权所有
E-mail:Webmaster@itpub.net
京ICP证:010037号 联系我们 法律顾问