CREATE OR REPLACE VIEW ikon.vw_lak AS 
 SELECT raw_data_lak.tahun,
    raw_data_lak.kd_provinsi,
    raw_data_lak.periode_id,
    raw_data_lak.kd_rek1,
    raw_data_lak.kd_rek2,
    raw_data_lak.kd_rek3,
    raw_data_lak.nm_rek1,
    raw_data_lak.nm_rek2,
    raw_data_lak.nm_rek3,
    sum(raw_data_lak.nilai) as nilai,
    raw_data_lak.dk
   FROM ikon.raw_data_lak 
   GROUP BY raw_data_lak.tahun, 
   raw_data_lak.kd_provinsi, 
   raw_data_lak.periode_id, 
   raw_data_lak.kd_rek1, 
   raw_data_lak.kd_rek2, 
   raw_data_lak.kd_rek3,
   raw_data_lak.nm_rek1,
   raw_data_lak.nm_rek2,
   raw_data_lak.nm_rek3,
   raw_data_lak.dk 
  ORDER BY raw_data_lak.kd_provinsi asc;


CREATE OR REPLACE VIEW ikon.vw_lpe AS select tahun,kd_provinsi,periode_id,
sum(ekuitas_awal) as ekuitas_awal,
sum(surplus_defisit) as surplus_defisit,
sum(koreksi_persediaan) as koreksi_persediaan,
sum(selisih_revaluasi_asset) as selisih_revaluasi_asset,
sum(lain_lain) as lain_lain,(sum(ekuitas_awal)+sum(surplus_defisit))
-(sum(koreksi_persediaan)+sum(selisih_revaluasi_asset)+sum(lain_lain)) as ekuitas_akhir from ikon.raw_data_lpe 
group by tahun,kd_provinsi,periode_id 
order by kd_provinsi asc;

CREATE OR REPLACE VIEW ikon.vw_lpsal AS select tahun,kd_provinsi,periode_id,
sum(saldo_awal) as saldo_awal,
sum(penggunaan_sal) as penggunaan_sal,
sum(silpa) as silpa,
sum(koreksi) as koreksi,
sum(lainnya) as lainnya, 
(sum(saldo_awal)-sum(penggunaan_sal))+(sum(silpa)+sum(koreksi)+sum(lainnya)) 
as saldo_akhir from ikon.raw_data_lpsal 
GROUP BY tahun,kd_provinsi,periode_id 
ORDER BY kd_provinsi ASC;