Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
14 views

SQL Query Script

Uploaded by

RadifanTaufikAce
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

SQL Query Script

Uploaded by

RadifanTaufikAce
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 2

-- NOMOR 1

select mp.nama_pegawai as "Employee",


count(no_so) as "Jumlah SO",
case
when count(no_so) >= mp.target then 'Tidak'
when count(no_so) < mp.target then 'Ya'
end "kurang dari target?"
from tr_so
left join master_pegawai mp
on mp.kode_pegawai = tr_so.kode_sales
group by nama_pegawai, kode_sales, mp.target
order by kode_sales

-- NOMOR 2
select a.no_do, a.tgl_do,a.qty,
(a.harga+a.ppn+a.ongkos_kirim) as amount
from (
select no_do, tgl_do,(ts.qty*mk.qty) as qty,
(ts.qty*mk.qty*mpr.harga_satuan) as harga,
(ts.qty*mk.qty*mpr.harga_satuan*10/100) as ppn,
mc.ongkos_kirim as ongkos_kirim
from tr_do as td
left join tr_so as ts
on ts.no_entry_so = td.no_entry_so
left join master_konversi as mk
on mk.satuan=ts.satuan
left join master_product as mpr
on mpr.kode_produk=ts.kode_barang
left join master_customer as mc
on mc.kode_customer=ts.kode_customer
) as a

-- NOMOR 3
select mc.nama_customer , td.no_do , td.tgl_do ,(ts.qty*mk.qty) as qty,
(('2018/02/01'::date) - (td.tgl_do::date)) as "umur hutang"
from tr_inv ti
right join tr_do td
on td.no_entry_do = ti.no_entry_do
left join tr_so ts
on ts.no_entry_so = td.no_entry_so
left join master_konversi mk
on mk.satuan = ts.satuan
left join master_product mp
on mp.kode_produk = ts.kode_barang
left join master_customer mc
on mc.kode_customer = ts.kode_customer
where ti.no_entry_do isnull

-- NOMOR 4
select a.nama_product,
sum(a.qty_converted) as quantity
from (
select mp.kode_produk , mp.nama_product, ts.qty, mk.qty as satuan_qty,
(ts.qty*mk.qty) as qty_converted
from tr_so ts
left join master_product mp
on mp.kode_produk = ts.kode_barang
left join master_konversi mk
on mk.satuan = ts.satuan
) as a
group by a.nama_product
order by quantity desc limit 3;

-- NOMOR 5
select a.vendor as "Nama Vendor", sum(a.amount) as "Amount"
from (
select mv.vendor,
(ts.qty*mk.qty*mp.harga_satuan) as amount
from tr_inv ti
left join tr_do td
on td.no_entry_do = ti.no_entry_do
left join tr_so ts
on ts.no_entry_so = td.no_entry_so
left join master_product mp
on mp.kode_produk = ts.kode_barang
left join master_konversi mk
on mk.satuan = ts.satuan
left join master_vendor mv
on mv.kode_vendor = mp.kode_vendor
) as a
group by a.vendor
order by "Amount" desc limit 3

You might also like