# 求学生在某几道题上的答题正确率

[@more@]r为正确答案，s为学生答案，th为题号，需用逗号分开
```代码:```
SQL> var r varchar2(10);
SQL> exec :r :='abcdabcd';

PL/SQL 过程已成功完成。

SQL>  var s varchar2(10);
SQL>  exec :s :='aabbccdd';

PL/SQL 过程已成功完成。

SQL>  var th varchar2(10);
SQL>  exec :th :='1,4,6';

PL/SQL 过程已成功完成。

SQL> select to_number(substr(:th,st+1,en-st-1)) th from (select decode(rn,1,0,in
str(:th,',',1,rn-1)) st ,decode(instr(:th,',',1,rn),0,length(:th)+1, instr(:th,'
,',1,rn)) en from (select rownum rn from dual connect by rownum<=length(:th)-len
gth(replace(:th,',',''))+1));

TH
----------
1
4
6

SQL> select count(*) zts, sum(case when substr(:r,th,1)=substr(:s,th,1) then 1 e
lse 0 end)/count(*) zql from (select to_number(substr(:th,st+1,en-st-1)) th from
(select decode(rn,1,0,instr(:th,',',1,rn-1)) st ,decode(instr(:th,',',1,rn),0,l
ength(:th)+1, instr(:th,',',1,rn)) en from (select rownum rn from dual connect b
y rownum<=length(:th)-length(replace(:th,',',''))+1)));

ZTS        ZQL
---------- ----------
3 .333333333

SQL> exec :th :='1,2,7,4,6';

PL/SQL 过程已成功完成。

SQL> /

ZTS        ZQL
---------- ----------
5         .2

SQL> exec :th :='1,2,7,5';

PL/SQL 过程已成功完成。

SQL> /

ZTS        ZQL
---------- ----------
4        .25
.......................................................``````

• 博文量
223
• 访问量
2812693