SELECT 1 AS `is_mig`
	   , TRIM(`users`.`KD_USER`) AS `nik` 
	   , TRIM(`users`.`NAMA_USER`) AS `name`
	   , TRIM(`users`.`EMAIL`) AS `email`
	   , TRIM(`users`.`TGL_UPDATE`) AS `updated_at`
	   , TRIM(`users`.`CHG_PASS`) AS `mig_chg_pass`
	   , TRIM(`users`.`FLAG_DATA`) AS `mig_flag_data`
	   , TRIM(`users`.`FLAG_OTO`) AS `mig_flag_oto`
	   , TRIM(`users`.`KD_CABANG`) AS `mig_kd_cabang`
	   , TRIM(`users`.`LAST_CHANGE_PASS`) AS `mig_last_change_pass`	   
	   , TRIM(`users`.`PASSWORD`) AS `mig_password`
	   , TRIM(`prm_user_access`.`STATUS`) AS `mig_status`
	   , TRIM(`users`.`TGL_OTO`) AS `mig_tgl_oto`
	   , TRIM(`users`.`TGL_UPDATE`) AS `mig_tgl_update`
	   , TRIM(`users`.`USER_OTO`) AS `mig_user_oto`
	   , TRIM(`users`.`USER_UPDATE`) AS `mig_user_update`
	   , TRIM(prm_user_access.KD_GROUP) AS 'mig_kd_group'
	   , TRIM(prm_group.NAMA_GROUP) AS 'mig_nama_group'
FROM `prm_user` AS `users`
JOIN `prm_user_access` ON `prm_user_access`.KD_USER=`users`.KD_USER
JOIN `prm_group` ON `prm_group`.KD_GROUP=prm_user_access.KD_GROUP
WHERE prm_user_access.KD_APPS='LPJ'
ORDER BY users.KD_USER

-- query total user pada setiap KD_GROUP
/*
SELECT 
    TRIM(prm_user_access.KD_GROUP) AS mig_kd_group,
    TRIM(prm_group.NAMA_GROUP) AS mig_nama_group,
    COUNT(DISTINCT TRIM(users.KD_USER)) AS total_users
FROM prm_user AS users
JOIN prm_user_access ON prm_user_access.KD_USER = users.KD_USER
JOIN prm_group ON prm_group.KD_GROUP = prm_user_access.KD_GROUP
WHERE prm_user_access.KD_APPS = 'LPJ'
GROUP BY prm_user_access.KD_GROUP, prm_group.NAMA_GROUP
ORDER BY prm_user_access.KD_GROUP;
*/