差异
select CE1.CLASS_ID,
CE1.LOCATION_ID,
count(case CE1.FORMAT_ID when 5 then 1 end) as LIVE,
count(case CE1.FORMAT_ID when 14 then 1 end) as LB,
count(case CE1.FORMAT_ID when 15 then 1 end) as WEB,
SUM(DECODE (CE1.ROLE_ID,5,1,0)) FACULTY,
SUM(DECODE (CE1.ROLE_ID ,2,1,0)) MODERATOR,
SUM(DECODE (CE1.ROLE_ID ,3,1,0)) PANELIST,
SUM(DECODE (CE1.ROLE_ID,4,1,0)) PRESENTER,
COUNT(CE1.USER_ID) TOT
from C_EDUCATION1 CE1
GROUP BY CE1.LOCATION_ID, CE1.CLASS_ID
我们正在开发现有系统,我们发现混合使用 COUNT 和 DECODE。如果我们理解正确,我们可以转换为以下代码。
select CE1.CLASS_ID,
CE1.LOCATION_ID,
SUM(DECODE (CE1.FORMAT_ID ,5,1,0)) LIVE,
SUM(DECODE (CE1.FORMAT_ID ,14,1,0)) LB,
SUM(DECODE (CE1.FORMAT_ID,15,1,0)) WEB,
SUM(DECODE (CE1.ROLE_ID,5,1,0)) FACULTY,
SUM(DECODE (CE1.ROLE_ID ,2,1,0)) MODERATOR,
SUM(DECODE (CE1.ROLE_ID ,3,1,0)) PANELIST,
SUM(DECODE (CE1.ROLE_ID,4,1,0)) PRESENTER,
COUNT(CE1.USER_ID) TOT
from C_EDUCATION1 CE1
GROUP BY CE1.LOCATION_ID, CE1.CLASS_ID
或全部计数
我们想知道性能差异或其他问题。存在更好的方法吗?