Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 2

masuk ke folder utama docker nya

docker-compose down
docker-compose up

//query MTD dengan generate series


SELECT date_trunc('day', dd):: date FROM generate_series( cast(date_trunc('month',
current_date) as date),
now(), '1 day'::interval)dd

//query menghitung umur


SELECT
AGE('2012-03-05', '2010-04-01'),
DATE_PART('year', AGE('2012-03-05', '2010-04-01')) AS years,
DATE_PART('month', AGE('2012-03-05', '2010-04-01')) AS months,
DATE_PART('day', AGE('2012-03-05', '2010-04-01')) AS days;

//kuery cek doble by pa oki


select * from karyawan where username in (select username from karyawan group by
username having count(username) > 1) order by username

//query update
UPDATE users SET full_name = replace(full_name, 'EDPEDP', 'EDP') where id = 3146

//query update pake pipe ||


update users set username = 'EDP'||username where id = 3146

select distinct username, full_name,initial_store,a.created_at::date from sources


a,users b where a.user_id=b.id and length(username) !=3 order by
created_at,initial_store,username;

select initial_store,created_at,count(*) from (select distinct username,


full_name,initial_store,a.created_at::date as created_at from sources a,users b
where a.user_id=b.id and length(username) !=3 order by initial_store,username) as
total group by initial_store,created_at order by created_at;

//ngisi yang kosong


update users set password =
'$2b$10$y4tt/28MRA3ih1VAY40Pf.oIfYZQra0GC3J3pSCdxMESyU5hKMv6i' where password=''

//Ngitung data yg sama di satu kolom


SELECT export_log, COUNT(export_log) AS jumlah FROM absen_log GROUP BY export_log
//cara ke 2 dan paling benar
select text_6, count(text_6) as jumlah from absen_log_temp group by text_6 having
count(text_6) > 1;

// mencari angka awal 20


select * from user where user_id like '20%'

// Update sequence
SELECT setval('users_id_seq', max(id)) FROM stores;

//copy antar table


INSERT INTO kirimdata (initial_store, machine_id, date_time, absen_code,
fingerprint_id, nik, export_log, created_at, updated_at)
SELECT absen_log.site_code, absen_log.mesin_id, absen_log.date_time,
absen_log.absen_code, absen_log.pin, karyawan.nik, 'now', 'now', 'now'
FROM absen_log
INNER JOIN karyawan ON absen_log.pin = karyawan.fingerprint_id;
//ngambil per regional
select * from machines where initial_store in (select initial from stores where
region_id = 1)

//join 2 field
select absen_log.*, karyawan.nik, karyawan.full_name from absen_log
join karyawan on(absen_log.pin = karyawan.fingerprint_id and
absen_log.site_code=karyawan.initial_store)

//query kyk grup by sum, tp ini nu string nu multiple dijadiin 1 baris


select initial_store,sku,sku_desc, sum(qty) as qty_count,
(select qty from trans_scan1 b where b.initial_store='BTL' and
scanning_type='scan_2' and b.sku=a.sku limit 1) as soh,
array_agg(distinct location_name) as location_name
from trans_scan1 a where initial_store='BTL' and scanning_type='scan_1'
group by sku,sku_desc,initial_store
order by sum(qty) desc

You might also like