You are on page 1of 2

SELECT X.

MERKNAMA, SUM(CASE WHEN KDJENISPOL = '701' THEN 1 ELSE 0 END) SOLE, SUM(CASE WHEN KDJENISPOL = '705' THEN 1 ELSE 0 END) KRT_SAMPING, SUM(CASE WHEN KDJENISPOL = '704' THEN 1 ELSE 0 END) SCOOTER, SUM(CASE WHEN KDJENISPOL = '706' THEN 1 ELSE 0 END) TRAIL, SUM(CASE WHEN KDJENISPOL = '702' THEN 1 ELSE 0 END) BENTOR, SUM(CASE WHEN KDJENISPOL not in ('701','702','704','705','706') THEN 1 EL SE 0 END) LAIN2, URUT FROM ( SELECT C.KDJENISPOL,C.NAJEN,A.MERKNAMA,B.NOREG_A,B.NOREG_B,B.NOREG_C,B.N OREG_D,B.NM_DITLANTAS,A.URUT FROM ( SELECT DISTINCT S.*, CASE WHEN MERKNAMA='SUZUKI' THEN 1 WHEN MERKNAMA='HONDA' THEN 2 WHEN MERKNAMA='YAMAHA' THEN 3 WHEN MERKNAMA='KAWASAKI' THEN 4 WHEN MERKNAMA='BAJAJ' THEN 5 WHEN MERKNAMA='KYMCO' THEN 6 WHEN MERKNAMA='KTM' THEN 7 WHEN MERKNAMA='TVS' THEN 8 WHEN MERKNAMA='SOIB' THEN 9 WHEN MERKNAMA='PIAGGIO' THEN 10 WHEN MERKNAMA='HYOSUNG' THEN 11 WHEN MERKNAMA='CAVIGA' THEN 12 WHEN MERKNAMA='SANEX' THEN 13 WHEN MERKNAMA='JIALING' THEN 14 WHEN MERKNAMA='SUMO' THEN 15 WHEN MERKNAMA='SUNDIRO' THEN 16 WHEN MERKNAMA='BATTLE' THEN 17 WHEN MERKNAMA='HARLEY' THEN 18 WHEN MERKNAMA='DUCATI' THEN 19 WHEN MERKNAMA='JRD' THEN 20 WHEN MERKNAMA='EMOTO' THEN 21 WHEN MERKNAMA='PHANTOM' THEN 22 WHEN MERKNAMA='HERO' THEN 23 WHEN MERKNAMA='VIAR' THEN 24 WHEN MERKNAMA='JIANSHE' THEN 25 WHEN MERKNAMA='KAISAR' THEN 26 WHEN MERKNAMA='DORKAS' THEN 27 ELSE 99 END URUT FROM ( SELECT KDMERK,CASE WHEN KDMERK IN ('364','167','421','213','034','224' ,'222','622','301', '505','327','196','358','360','039','150','106','201','597','158','396 ','197','205') THEN TRIM(MERKNAMA) ELSE 'LAIN-LAIN' END MERKNAMA FROM STMERK ) S order by urut ) A LEFT JOIN (SELECT DISTINCT NOREG_A,NOREG_B,NOREG_C,NOREG_D,NM_DITLANT AS,KDMERK,KDJENISPOL,trunc(TGPROSES) as TGPROSES FROM BPKB_DETAIL) B ON (A.KDMERK=B.KDMERK and B.TGPROSES between to_date('01/06/2010','dd/m m/yyyy') and to_date('30/06/2010','dd/mm/yyyy') and kdjenispol between '701' and '799') LEFT JOIN STJENIS C ON (B.KDJENISPOL=C.KDJENISPOL) ) X GROUP BY MERKNAMA,URUT ORDER BY URUT

================================ SELECT X.MERK, SUM(CASE WHEN NAJEN = 'SEDAN' THEN 1 ELSE 0 END) SEDAN, SUM(CASE WHEN NAJEN = 'STATION WAGON' THEN 1 ELSE 0 END) SW, SUM(CASE WHEN NAJEN = 'MINIBUS' THEN 1 ELSE 0 END) MINBUS, SUM(CASE WHEN NAJEN = 'JEEP' THEN 1 ELSE 0 END) JP, SUM(CASE WHEN NAJEN = 'B U S' THEN 1 ELSE 0 END) BUS, SUM(CASE WHEN NAJEN = 'MICROBUS' THEN 1 ELSE 0 END) MICBUS, SUM(CASE WHEN NAJEN = 'BUS GANDENG' THEN 1 ELSE 0 END) BG, SUM(CASE WHEN NAJEN = 'PICK UP' THEN 1 ELSE 0 END) PU, SUM(CASE WHEN NAJEN = 'DELIVER VAN' THEN 1 ELSE 0 END) DV, SUM(CASE WHEN NAJEN = 'T R U C K' THEN 1 ELSE 0 END) TRUCK, SUM(CASE WHEN NAJEN = 'TRUCK TANGKI' THEN 1 ELSE 0 END) TT, SUM(CASE WHEN NAJEN = 'DOUBLE CABIN' THEN 1 ELSE 0 END) DC, SUM(CASE WHEN NAJEN = 'PEMADAM KEBAKARAN' THEN 1 ELSE 0 END) PK, SUM(CASE WHEN NAJEN = 'AMBULANCE' THEN 1 ELSE 0 END) AB, SUM(CASE WHEN NAJEN = 'MOBIL JENASAH' THEN 1 ELSE 0 END) MJ, SUM(CASE WHEN NAJEN = 'FORKLIFT' THEN 1 ELSE 0 END) FL, URUT FROM ( SELECT S.*, CASE WHEN URUT<=10 THEN MERKNAMA ELSE 'LAIN-LAIN' END MERK FROM ( SELECT ROWNUM AS URUT,A.*,B.MERKNAMA FROM (SELECT DISTINCT X.NOREG_A,X .NOREG_B,X.NOREG_C,X.NOREG_D,X.NM_DITLANTAS,X.KDMERK,X.KDJENISPOL,TRUNC(X.TGPROS ES) AS TGPROSES,COUNT(*) AS JML FROM BPKB_DETAIL X GROUP BY X.NOREG_A,X.NOREG_B,X.NOREG_C,X.NOREG_D,X.NM _DITLANTAS,X.KDMERK,X.KDJENISPOL,TGPROSES ORDER BY JML) A LEFT JOIN STMERK B ON (A.KDMERK=B.KDMERK) )S )X LEFT JOIN BPKB_MASTER Z ON (X.NOREG_A=Z.NOREG_A AND X.NOREG_B=Z.NOREG _B AND X.NOREG_C=Z.NOREG_C AND X.NOREG_D=Z.NOREG_D AND X.NM_DITLANTAS=Z.NM_DITLA NTAS) LEFT JOIN (SELECT T.NOBPKBA,T.NOBPKB,T.NOBPKBC,COUNT(*) FROM BPKB_CETAK T G ROUP BY T.NOBPKBA,T.NOBPKB,T.NOBPKBC HAVING COUNT(*)>4) XX ON (TRIM(Z.NOBPKBA||Z .NOBPKB||Z.NOBPKBC)=TRIM(XX.NOBPKBA||XX.NOBPKB||XX.NOBPKBC)) LEFT JOIN ( SELECT KDJENISPOL,CASE WHEN KDJENISPOL IN ('101','103','102','20 2', '201','301','301','413','401','435','701','704', '513','502','504','614','105','705','706') THEN NAJEN WHEN KDJENISPOL IN ('203') THEN 'BUS GANDENG' WHEN KDJENISPOL IN ('352','417','404','351','432 ') THEN 'T R U C K' WHEN KDJENISPOL IN ('434') THEN 'TRUCK TANGKI' WHEN KDJENISPOL IN ('303') THEN 'PICK UP' WHEN KDJENISPOL IN ('304','305') THEN 'DOUBLE CA BIN' ELSE 'LAIN-LAIN' END NAJEN,NAJENPOL FROM STJENIS ) YY ON (X.KDJENISPOL=YY.KDJENISPOL) WHERE XX.NOBPKBA IS NOT NULL AND X.TGPROSES BETWEEN TO_DATE('01/06/2010','DD/MM /YYYY') AND TO_DATE('30/06/2010','DD/MM/YYYY') AND X.KDJENISPOL<'700' GROUP BY MERK,URUT ORDER BY URUT