SELECT c.dmedia_name,COUNT(a.job_no) AS QTY,
min(case cust_name when 'GDMX' then cust_name end) as GDMX,
min(case cust_name when 'CANON VIETNAM CO.,LTD.' then cust_name end) as [CANON VIETNAM CO.,LTD.],
min(case cust_name when 'IMPLANT MEDIA PTY. LTD.' then cust_name end) as [IMPLANT MEDIA PTY. LTD.]
FROM tbl_download a
INNER JOIN tbl_download_log b ON b.job_no = a.job_no
INNER JOIN tbl_customer ON a.cust_code = tbl_customer.cust_code
INNER JOIN tbl_download_media AS c on a.dmedia_code=c.dmedia_code
WHERE ({ fn CONCAT(SUBSTRING(b.dlog_date, 4, 2), SUBSTRING(b.dlog_date, 7, 4)) } BETWEEN 052012 AND 052012) AND (b.dlog_even = 'Finish')
GROUP BY tbl_customer.cust_name,c.dmedia_name
ORDER BY c.dmedia_name
SELECT c.dmedia_name,
COUNT(case d.cust_name when 'GDMX' then d.cust_name end) as GDMX,
COUNT(case d.cust_name when 'CANON VIETNAM CO.,LTD.' then d.cust_name end) as [CANON VIETNAM CO.,LTD.],
COUNT(case d.cust_name when 'IMPLANT MEDIA PTY. LTD.' then d.cust_name end) as [IMPLANT MEDIA PTY. LTD.]
FROM tbl_download as a
INNER JOIN tbl_download_log as b ON b.job_no = a.job_no
INNER JOIN tbl_customer as d ON a.cust_code = d.cust_code
INNER JOIN tbl_download_media AS c on a.dmedia_code=c.dmedia_code
WHERE ({ fn CONCAT(SUBSTRING(b.dlog_date, 4, 2), SUBSTRING(b.dlog_date, 7, 4)) } BETWEEN 052012 AND 052012) AND (b.dlog_even = 'Finish')
GROUP BY d.cust_name,c.dmedia_name
ORDER BY c.dmedia_name