berikut contoh script untuk menggroupkan issue berdasarkan hari di MYSQL, sejenis pivot tabel atau cross-tab :
select a.com_desc,
sum(CASE WHEN a.nama_berita = 'ACT' THEN cnt ELSE 0 END ) ACT,
sum(CASE WHEN a.nama_berita = 'VMI' THEN cnt ELSE 0 END ) VMI,
sum(CASE WHEN a.nama_berita = 'Network' THEN cnt ELSE 0 END ) Network,
sum(CASE WHEN a.nama_berita = 'Email' THEN cnt ELSE 0 END ) Email,
sum(CASE WHEN a.nama_berita = 'Others' THEN cnt ELSE 0 END ) Others,
sum(CASE WHEN a.nama_berita = 'Hardware' THEN cnt ELSE 0 END ) Hardware,
sum(CASE WHEN a.nama_berita = 'Software' THEN cnt ELSE 0 END ) Software,
sum(CASE WHEN a.nama_berita = 'Internet' THEN cnt ELSE 0 END ) Internet
from
( SELECT t_day.com_desc , t_day.com_code , berita.nama_berita, count( berita.nama_berita ) cnt
FROM t_day LEFT JOIN berita ON com_desc = hari
and berita.tgl_berita >'2000-12-31'
GROUP BY t_day.com_desc , berita.nama_berita
ORDER BY t_day.com_code
)a
group by a.com_desc
order by a.com_code desc
Thursday, February 05, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment