SQL表里有管理类(有5个人),客服类(3人),要查出管理类的人占总人数的比例.

来源:百度知道 编辑:UC知道 时间:2024/05/15 11:55:47
要显示为百分数"?%"

在sqlserver中:
select count(*),
convert(varchar(2),round(count(*)/(select count(*) from tabname),2)*100)+'%'
from tabname
where type='manage'

在oracle中:
select count(*),
to_char(round(count(*)/(select count(*) from tabname),2)*100)||'%'
from tabname
where type='manage'

祝你武运长久

select cast(round((count(*)/(select count(*) from biao))*100,0) as varchar) from biao where 类别='管理类'