说明:
这条sql是在一张表里面进行查询,将不同的级别的工程师的百分率查询出来
第一个sql
select
tmp.job_grade, tmp.tcount/tmp1.t1count
from
(
select job_grade,count(*) tcount from cscp_exam_apply GROUP BY job_grade ) tmp
join
(select job_grade,count(*) t1count from cscp_exam_apply where result='P' GROUP BY job_grade) tmp1
on tmp.job_grade=tmp1.job_grade
第二个sql
select
tmp.ContentTypeID, tmp.tcount/tmp1.t1count
from
(
select ContentTypeID,count(*) tcount from zccontent WHERE CatalogID=18666 GROUP BY ContentTypeID ) tmp
join
(select ContentTypeID,count(*) t1count from zccontent where CatalogID=18668 GROUP BY ContentTypeID) tmp1
on tmp.ContentTypeID=tmp1.ContentTypeID
执行的结果:
tmp.ContentTypeID | tmp.tcount/tmp1.t1count |
---|---|
高级工程师 | 3.000 |
中级工程师 | 2.000 |
低级工程师 | 1.0000 |
这条sql语句的注意事项:
方式二的百分比的sql说明:
这个是不需要进行分组的百分率sql.
select (select count(*) from zccontent where CatalogID=18666 )/(select count(*) from zccontent where CatalogID=18668 ) Acount
执行的结果为
Acount |
---|
0.0725 |
#这个是说明每种值的数量
select greate,COUNT(*) from class GROUP BY greate
#这个sql是说明每种值的概率
select greate,COUNT(*)/11 from class GROUP BY greate #这里的11是该表的总行数
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)