select name,sum(decode(number,1,math,0)) 1,
sum(decode(number,2,math,0)) 2,
sum(decode(number,3,math,0)) 3
from tbname group by name;
sum(decode(number,2,math,0)) 2,
sum(decode(number,3,math,0)) 3
from tbname group by name;
调试欢乐多
FROM TABLE_NAME
GROUP BY NAME
以上在oracle调度通过,表名为T_Marks 可以达到你的目的!
以下为执行情况:
SQL> select name,sum(decode(num,1,math,0)) as "1",sum(decode(num,2,math,0)) as "2",sum(decode(num,3,math,0)) as "3" from t_s group by name;NAME 1 2 3
-------------------- ---------- ---------- ----------
小华 98 75 0
小明 80 90 61