Decode is actually if-else, such as decode (ybc, null, 0, ybc). This means that if the ybc column is null, the function returns 0; otherwise, the function returns ybc. Another example is decode (variable, condition, condition). This means: if-elsif. if it is decode (variable, condition, condition, 3 ), this is if-elsif-else
Decode is actually if-else, such as decode (ybc, null, 0, ybc). This means that if the ybc column = null, the function returns 0; otherwise, the function returns ybc. Another example is decode (variable, condition, condition). This means: if-elsif. if it is decode (variable, condition, condition, 3 ), this is if-elsif-else
Decode is actually if-else, such as decode (ybc, null, 0, ybc). This means that if the ybc column is = null, the function returns 0, otherwise, the value of ybc is returned.
Another example is decode (variable, condition 1, value 1, condition 2, value 2). This means: if-elsif. if it is decode (variable, condition 1, value 1, condition 2, value 2, value 3), which is if-elsif-else.
A specific reference for oracle row-to-column: http://www.2cto.com/database/201108/100792.html
The following is the code:
insert into tj_kszgjf(id,bjdm,xxdm,xqdm,dsdm,ybc,xxtj,xqtj,dstj,tj_kszgjf.zstg,tj_kszgjf.sum, shijian,flag)select seq_kszgjftj.nextval,bj.bjdm,bj.xx_xxdm as xxdm,xx.xq_xqdm as xqdm,xq.ss as dqdm, decode(ybc,null,0,ybc), decode(xxtj,null,0,xxtj), decode(xqtj,null,0,xqtj), decode(dstj,null,0,dstj), decode(zstg,null,0,zstg), decode("sum",null,0,"sum"), sysdate,flagfrom (select zgjf.bjdm, sum(decode(zgjf.zt, 1,1,0)) ybc, sum(decode(zgjf.zt, 2, 1,0)) xxtj, sum(decode(zgjf.zt, 3, 1,0)) xqtj, sum(decode(zgjf.zt, 4, 1,0)) dstj, sum(decode(zgjf.zt, 5, 1,0)) zstg, count(bmxh)as "sum", flag from zgjf group by flag,bjdm )zgjftempright join bj on zgjftemp.bjdm=bj.bjdminner join xx on bj.xx_xxdm=xx.zxdminner join xq on xx.xq_xqdm=xq.xqdm;commit;