select allnum,sucessnum from mytabl;
现在想在查询处增加一列:成功率(用百分比,小数点保留两位数字)
select allnum,sucessnum,sucessnum/allnum from mytabl; 这样不能实现我想要的效果
11 个解决方案
#1
select allnum,sucessnum,
round(sucessnum*100/allnum,2)||'%' as 成功率
from mytabl;
#2
select allnum,sucessnum,to_char(sucessnum/allnum,'99D99')||'%' from mytabl;
试试看
#3
上面的错了,更正一下:
select allnum,sucessnum,to_char((sucessnum/allnum)*100,'99D99')||'%' from mytabl;
#4
SQL> select * from t3;
ALLNUM SUCESSNUM
---------- ----------
88 43
53 20
57 23
76 21
SQL> select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' percent from t3;
ALLNUM SUCESSNUM PERCENT
---------- ---------- -----------------------------------------
88 43 48.86%
53 20 37.74%
57 23 40.35%
76 21 27.63%
SQL>
#5
楼上的太细致了,佩服
#6
select allnum,sucessnum,to_char(100 * sucessnum/allnum, 'fm99999990.00') || '%' from mytabl
#7
方法一:select allnum,sucessnum,to_char((sucessnum/allnum)*100,'99D99')||'%' from mytabl;
方法二:select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' 成功率 from mytabl;
两种方法均可,我已测试过
方法二:select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' 成功率 from mytabl;
两种方法均可,我已测试过
#8
SQL> select * from t3;
ALLNUM SUCESSNUM
---------- ----------
88 43
53 20
57 23
76 21
SQL> select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' percent from t3;
ALLNUM SUCESSNUM PERCENT
---------- ---------- -----------------------------------------
88 43 48.86%
53 20 37.74%
57 23 40.35%
76 21 27.63%
SQL>
SQL> select * from t3;
ALLNUM SUCESSNUM
---------- ----------
88 43
53 20
57 23
76 21
SQL> select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' percent from t3;
ALLNUM SUCESSNUM PERCENT
---------- ---------- -----------------------------------------
88 43 48.86%
53 20 37.74%
57 23 40.35%
76 21 27.63%
SQL>
SQL> select * from t3;
ALLNUM SUCESSNUM
---------- ----------
88 43
53 20
57 23
76 21
SQL> select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' percent from t3;
ALLNUM SUCESSNUM PERCENT
---------- ---------- -----------------------------------------
88 43 48.86%
53 20 37.74%
57 23 40.35%
76 21 27.63%
SQL>
ALLNUM SUCESSNUM
---------- ----------
88 43
53 20
57 23
76 21
SQL> select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' percent from t3;
ALLNUM SUCESSNUM PERCENT
---------- ---------- -----------------------------------------
88 43 48.86%
53 20 37.74%
57 23 40.35%
76 21 27.63%
SQL>
SQL> select * from t3;
ALLNUM SUCESSNUM
---------- ----------
88 43
53 20
57 23
76 21
SQL> select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' percent from t3;
ALLNUM SUCESSNUM PERCENT
---------- ---------- -----------------------------------------
88 43 48.86%
53 20 37.74%
57 23 40.35%
76 21 27.63%
SQL>
SQL> select * from t3;
ALLNUM SUCESSNUM
---------- ----------
88 43
53 20
57 23
76 21
SQL> select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' percent from t3;
ALLNUM SUCESSNUM PERCENT
---------- ---------- -----------------------------------------
88 43 48.86%
53 20 37.74%
57 23 40.35%
76 21 27.63%
SQL>
#9
我同意四楼的,但在正常情况下allnum不会为0,如果非正常情况呢,所以我做了一下改动
select allnum,SUCESSNUM,decode(allnum 0,0,round((SUCESSNUM/allnum)*100,2)||'%') percent from t3;
select allnum,SUCESSNUM,decode(allnum 0,0,round((SUCESSNUM/allnum)*100,2)||'%') percent from t3;
#10
RoundZ就可以了
#11
这个貌似有点问题.
#1
select allnum,sucessnum,
round(sucessnum*100/allnum,2)||'%' as 成功率
from mytabl;
#2
select allnum,sucessnum,to_char(sucessnum/allnum,'99D99')||'%' from mytabl;
试试看
#3
上面的错了,更正一下:
select allnum,sucessnum,to_char((sucessnum/allnum)*100,'99D99')||'%' from mytabl;
#4
SQL> select * from t3;
ALLNUM SUCESSNUM
---------- ----------
88 43
53 20
57 23
76 21
SQL> select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' percent from t3;
ALLNUM SUCESSNUM PERCENT
---------- ---------- -----------------------------------------
88 43 48.86%
53 20 37.74%
57 23 40.35%
76 21 27.63%
SQL>
#5
楼上的太细致了,佩服
#6
select allnum,sucessnum,to_char(100 * sucessnum/allnum, 'fm99999990.00') || '%' from mytabl
#7
方法一:select allnum,sucessnum,to_char((sucessnum/allnum)*100,'99D99')||'%' from mytabl;
方法二:select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' 成功率 from mytabl;
两种方法均可,我已测试过
方法二:select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' 成功率 from mytabl;
两种方法均可,我已测试过
#8
SQL> select * from t3;
ALLNUM SUCESSNUM
---------- ----------
88 43
53 20
57 23
76 21
SQL> select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' percent from t3;
ALLNUM SUCESSNUM PERCENT
---------- ---------- -----------------------------------------
88 43 48.86%
53 20 37.74%
57 23 40.35%
76 21 27.63%
SQL>
SQL> select * from t3;
ALLNUM SUCESSNUM
---------- ----------
88 43
53 20
57 23
76 21
SQL> select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' percent from t3;
ALLNUM SUCESSNUM PERCENT
---------- ---------- -----------------------------------------
88 43 48.86%
53 20 37.74%
57 23 40.35%
76 21 27.63%
SQL>
SQL> select * from t3;
ALLNUM SUCESSNUM
---------- ----------
88 43
53 20
57 23
76 21
SQL> select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' percent from t3;
ALLNUM SUCESSNUM PERCENT
---------- ---------- -----------------------------------------
88 43 48.86%
53 20 37.74%
57 23 40.35%
76 21 27.63%
SQL>
ALLNUM SUCESSNUM
---------- ----------
88 43
53 20
57 23
76 21
SQL> select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' percent from t3;
ALLNUM SUCESSNUM PERCENT
---------- ---------- -----------------------------------------
88 43 48.86%
53 20 37.74%
57 23 40.35%
76 21 27.63%
SQL>
SQL> select * from t3;
ALLNUM SUCESSNUM
---------- ----------
88 43
53 20
57 23
76 21
SQL> select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' percent from t3;
ALLNUM SUCESSNUM PERCENT
---------- ---------- -----------------------------------------
88 43 48.86%
53 20 37.74%
57 23 40.35%
76 21 27.63%
SQL>
SQL> select * from t3;
ALLNUM SUCESSNUM
---------- ----------
88 43
53 20
57 23
76 21
SQL> select allnum,SUCESSNUM,round((SUCESSNUM/allnum)*100,2)||'%' percent from t3;
ALLNUM SUCESSNUM PERCENT
---------- ---------- -----------------------------------------
88 43 48.86%
53 20 37.74%
57 23 40.35%
76 21 27.63%
SQL>
#9
我同意四楼的,但在正常情况下allnum不会为0,如果非正常情况呢,所以我做了一下改动
select allnum,SUCESSNUM,decode(allnum 0,0,round((SUCESSNUM/allnum)*100,2)||'%') percent from t3;
select allnum,SUCESSNUM,decode(allnum 0,0,round((SUCESSNUM/allnum)*100,2)||'%') percent from t3;
#10
RoundZ就可以了
#11
这个貌似有点问题.