用sql怎么计算完成率百分号
这是我写的查询语句selectb.dept_name,count(a.CNS_INS_ID)asxinxiyuan,c.bianji,count(casewhena.CN...
这是我写的查询语句
select
b.dept_name,
count(a.CNS_INS_ID) as xinxiyuan,
c.bianji,
count(case when a.CNS_DIAL_NUMBER > 0 then '已拨打' end) as yiwancheng,
count(case when a.CNS_DIAL_NUMBER is NULL then '未拨打' end) as weiwancheng
from LZ_COUNT_SOURCES_yue a
left join lz_department b on a.dept_id =b.dept_id
left join
(
select count(admin_id ) as bianji,dept_id from lz_admin
group by dept_id
) c on b.dept_id = c.dept_id
where a.parent_id = 60
group by b.dept_name,c.bianji
怎么算出yiwancheng除以xinxiyuan的百分比 展开
select
b.dept_name,
count(a.CNS_INS_ID) as xinxiyuan,
c.bianji,
count(case when a.CNS_DIAL_NUMBER > 0 then '已拨打' end) as yiwancheng,
count(case when a.CNS_DIAL_NUMBER is NULL then '未拨打' end) as weiwancheng
from LZ_COUNT_SOURCES_yue a
left join lz_department b on a.dept_id =b.dept_id
left join
(
select count(admin_id ) as bianji,dept_id from lz_admin
group by dept_id
) c on b.dept_id = c.dept_id
where a.parent_id = 60
group by b.dept_name,c.bianji
怎么算出yiwancheng除以xinxiyuan的百分比 展开
1个回答
展开全部
select *,cast(round((yiwancheng/xinxiyuan),2)*100 as varchar(20))+'%' as baifenbi from (
select
b.dept_name,
count(a.CNS_INS_ID) as xinxiyuan,
c.bianji,
count(case when a.CNS_DIAL_NUMBER > 0 then '已拨打' end) as yiwancheng,
count(case when a.CNS_DIAL_NUMBER is NULL then '未拨打' end) as weiwancheng
from LZ_COUNT_SOURCES_yue a
left join lz_department b on a.dept_id =b.dept_id
left join
(
select count(admin_id ) as bianji,dept_id from lz_admin
group by dept_id
) c on b.dept_id = c.dept_id
where a.parent_id = 60
group by b.dept_name,c.bianji) as temp
select
b.dept_name,
count(a.CNS_INS_ID) as xinxiyuan,
c.bianji,
count(case when a.CNS_DIAL_NUMBER > 0 then '已拨打' end) as yiwancheng,
count(case when a.CNS_DIAL_NUMBER is NULL then '未拨打' end) as weiwancheng
from LZ_COUNT_SOURCES_yue a
left join lz_department b on a.dept_id =b.dept_id
left join
(
select count(admin_id ) as bianji,dept_id from lz_admin
group by dept_id
) c on b.dept_id = c.dept_id
where a.parent_id = 60
group by b.dept_name,c.bianji) as temp
追答
那是因为你的数字可能是字符,改一下这句
cast(round((cast(yiwancheng as int)/cast(xinxiyuan as int)),2)*100 as varchar(20))+'%' as baifenbi
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |