換另一種思維模式,其實用JOIN方式也可以達到相同效果
不過join時須小心"卡式積"效應....
SELECT T1.SPNO,T1.ITEMS,T1.SIZE01,T2.SIZE02,T3.SIZE03,T4.SIZE04,T5.SIZE05,T6.SIZE06,T7.SIZE07
,T8.SIZE08,T9.SIZE09,TA.SIZE10,TB.SIZE11,TC.SIZE12,TD.SIZE13,TE.SIZE14
FROM
(select SPNO,ITEMS,SIZES SIZE01 from FDRTDSIZE WHERE COLS='01' ) T1
LEFT JOIN ( SELECT SPNO,ITEMS,SIZES SIZE02 from FDRTDSIZE WHERE COLS='02' ) T2 ON T1.ITEMS=T2.ITEMS AND T1.SPNO=T2.SPNO
LEFT JOIN ( SELECT SPNO,ITEMS,SIZES SIZE03 from FDRTDSIZE WHERE COLS='03' ) T3 ON T1.ITEMS=T3.ITEMS AND T1.SPNO=T3.SPNO
LEFT JOIN ( SELECT SPNO,ITEMS,SIZES SIZE04 from FDRTDSIZE WHERE COLS='04' ) T4 ON T1.ITEMS=T4.ITEMS AND T1.SPNO=T4.SPNO
LEFT JOIN ( SELECT SPNO,ITEMS,SIZES SIZE05 from FDRTDSIZE WHERE COLS='05' ) T5 ON T1.ITEMS=T5.ITEMS AND T1.SPNO=T5.SPNO
LEFT JOIN ( SELECT SPNO,ITEMS,SIZES SIZE06 from FDRTDSIZE WHERE COLS='06' ) T6 ON T1.ITEMS=T6.ITEMS AND T1.SPNO=T6.SPNO
LEFT JOIN ( SELECT SPNO,ITEMS,SIZES SIZE07 from FDRTDSIZE WHERE COLS='07' ) T7 ON T1.ITEMS=T7.ITEMS AND T1.SPNO=T7.SPNO
LEFT JOIN ( SELECT SPNO,ITEMS,SIZES SIZE08 from FDRTDSIZE WHERE COLS='08' ) T8 ON T1.ITEMS=T8.ITEMS AND T1.SPNO=T8.SPNO
LEFT JOIN ( SELECT SPNO,ITEMS,SIZES SIZE09 from FDRTDSIZE WHERE COLS='09' ) T9 ON T1.ITEMS=T9.ITEMS AND T1.SPNO=T9.SPNO
LEFT JOIN ( SELECT SPNO,ITEMS,SIZES SIZE10 from FDRTDSIZE WHERE COLS='10' ) TA ON T1.ITEMS=TA.ITEMS AND T1.SPNO=TA.SPNO
LEFT JOIN ( SELECT SPNO,ITEMS,SIZES SIZE11 from FDRTDSIZE WHERE COLS='11' ) TB ON T1.ITEMS=TB.ITEMS AND T1.SPNO=TB.SPNO
LEFT JOIN ( SELECT SPNO,ITEMS,SIZES SIZE12 from FDRTDSIZE WHERE COLS='12' ) TC ON T1.ITEMS=TC.ITEMS AND T1.SPNO=TC.SPNO
LEFT JOIN ( SELECT SPNO,ITEMS,SIZES SIZE13 from FDRTDSIZE WHERE COLS='13' ) TD ON T1.ITEMS=TD.ITEMS AND T1.SPNO=TD.SPNO
LEFT JOIN ( SELECT SPNO,ITEMS,SIZES SIZE14 from FDRTDSIZE WHERE COLS='14' ) TE ON T1.ITEMS=TE.ITEMS AND T1.SPNO=TE.SPNO
沒有留言:
張貼留言