Social Icons

Pages

Selasa, 22 Oktober 2013

Worksheet DML (Data Manipulation Language) Part 2


1) Tampilkan 2 data produk termahal

dbkoperasi=# select * from produk order by harga desc limit 2;

2) Tampilkan produk yang paling murah

dbkoperasi=# select * from produk order by harga asc limit 1;

3) Tampilkan customer yang paling muda

dbkoperasi=# select nama, tgl_lahir, age(current_date, tgl_lahir) from customer order by tgl_lahir desc limit 1;

4) Tampilkan customer yang paling tua

dbkoperasi=# select nama, tgl_lahir, age(current_date, tgl_lahir) from customer order by tgl_lahir asc limit 1;

5) Berapa jumlah customer yang tahun lahirnya 2005
    
      dbkoperasi=# select count(id) as jumlah_customer from customer where date_part('year', tgl_lahir) = 2005;

6) Berapa jumlah data custumer perempuan yang tempat lahirnya di Jakarta

     dbkoperasi=# select count(id) as jumlah_customer from customer where gender = 'P' and alamat = 'Jakarta';
      
      dbkoperasi=# select count(id) as jumlah_customer from customer where gender = 'P' and upper(alamat) = 'JAKARTA';

      dbkoperasi=# select count(id) as jumlah_customer from customer where gender = 'P' and alamat = 'Jakarta';

7) Berapa jumlah total stok semua produk yang harganya dibawah 10rb

    dbkoperasi=# select sum(stok) as total_stok from produk where harga < 10000;

8) Ada berapa produk yang harganya diatas 1jt

    dbkoperasi=# select count(id) as jumlah_produk from produk where harga > 1000000;

9) Ada berapa produk yang mempunyai kode awal K

    dbkoperasi=# select count(id) as kode_produk from produk where kode ilike 'K%' ;

10) Berapa harga rata-rata produk yang diatas 1jt
     
       dbkoperasi=# select avg(harga) as harga_produk from produk where harga > 1000000;

11) Tampilkan jumlah stok yang paling besar

     dbkoperasi=# select max(stok) as jumlah_stok from produk;

12) Ada berapa produk yang stoknya kurang

     dbkoperasi=# select count(id) as jumlah_stok from produk where stok < min_stok;

13) Berapa total asset dari keseluruhan produk

     dbkoperasi=# select sum(harga*stok) as asset from produk;

14) berapa rata-rata stok yang harganya diantara 1jt sampa 4 jt

      dbkoperasi=# select avg(stok) as rata2_stok_produk from produk where harga between 1000000 and 4000000;

15) Tampilkan jumlah statistik customer berdasarkan tempat kelahiran customer 
 
      dbkoperasi=# select distinct(alamat) as kota_kelahiran from customer 

16) Tampilkan jumlah statistik produk berdasarkan jenis produk

       dbkoperasi=# select jenis_produk_id, count(id) as jumlah from produk group by jenis_produk_id;

Tidak ada komentar:

Posting Komentar