用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的百分比
展开
 我来答
百度网友7558ae7
2014-11-05 · TA获得超过5797个赞
知道小有建树答主
回答量:1730
采纳率:50%
帮助的人:1685万
展开全部
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
追问

为什么算出来都是0呢,没有数

追答
那是因为你的数字可能是字符,改一下这句
cast(round((cast(yiwancheng as int)/cast(xinxiyuan as int)),2)*100 as varchar(20))+'%' as baifenbi
本回答被提问者和网友采纳
已赞过 已踩过<
你对这个回答的评价是?
评论 收起
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式