select studentid,resourceTypeID,resourceCount from studentResourceAccept
结果: studentid resourceTypeID resourceCount (sfz,身份证,zzz,暂住证,zp,照片,wjz外交正,jgz,军官证)
240011 sfz 1
240011 zp 8
240011 zzz 1 250011 wjz 1
250011 jgz 1
想要的结果: studentid TypeID1 Count1 TypeID2 Count2 TypeID3 Count3 typeID4 count4 typeid5 count5
240011 sfz 1 zp 8 zzz 1 250011 wjz 1 jgz 1sql语句如何写?? 在线等,急~~~~~~~~~~
结果: studentid resourceTypeID resourceCount (sfz,身份证,zzz,暂住证,zp,照片,wjz外交正,jgz,军官证)
240011 sfz 1
240011 zp 8
240011 zzz 1 250011 wjz 1
250011 jgz 1
想要的结果: studentid TypeID1 Count1 TypeID2 Count2 TypeID3 Count3 typeID4 count4 typeid5 count5
240011 sfz 1 zp 8 zzz 1 250011 wjz 1 jgz 1sql语句如何写?? 在线等,急~~~~~~~~~~
sum(case resourceTypeID when 'sfz' then 1 else 0 end) sfz,
sum(case resourceTypeID when 'zzz' then 1 else 0 end) zzz,
sum(case resourceTypeID when 'zp' then 1 else 0 end) zp,
sum(case resourceTypeID when 'wjz' then 1 else 0 end) wjz,
sum(case resourceTypeID when 'jgz' then 1 else 0 end) jgz
from tb
group by studentid
insert into ttt values('240011','sfz',1);
insert into ttt values('240011','zp',8);
insert into ttt values('240011','zzz',1);
insert into ttt values('250011','wjz',1);
insert into ttt values('250011','jgz',1);
select studentid,
'sfz',sum(decode(resourcetypeid,'sfz',resourcecount,0)) count1,
'zzz',sum(decode(resourcetypeid,'zzz',resourcecount,0)) count2,
'zp',sum(decode(resourcetypeid,'zp',resourcecount,0)) count3,
'wjz',sum(decode(resourcetypeid,'wjz',resourcecount,0)) count4,
'jgz',sum(decode(resourcetypeid,'jgz',resourcecount,0)) count5
from
ttt
group by studentid