Pivot Tabel Absen Finger print

23:12 Unknown 0 Comments

Membuat Pivot dari data absen finger

jika kita punya data absen finger seperti di bawah



lalu kita buat syntax sql nya

select no_absen,
  max(case when rownum = 1 then checktime end) Date1,
  max(case when rownum = 2 then checktime end) Date2,
  max(case when rownum = 3 then checktime end) Date3,
  max(case when rownum = 4 then checktime end) Date4
from(
select absenfinger.no_absen,
    absenfinger.checktime,
    @row:=if(@prev=date_format(absenfinger.checktime,'%Y-%m-%d'), @row,0) + 1 as rownum,
    @prev:=date_format(absenfinger.checktime,'%Y-%m-%d') as date
  from absenfinger JOIN rencanakerja ON absenfinger.no_absen = rencanakerja.no_absen,(SELECT @row:=0, @prev:=null) r
  WHERE date_format(absenfinger.checktime,'%Y-%m-%d')=date_format(rencanakerja.tanggal,'%Y-%m-%d')
    )s
    GROUP BY date
  order by no_absen, checktime

ini baru pivot static belum dinamis bray..





















0 comments: