mysql> create database toko;
mysql> use toko;
Database changed
Membuat
Tabel pembeli
mysql> create table pembeli(Id_pembeli
int(10),nama varchar(20), alamat varchar(20), kode varchar(10));
Memasukkan
data pembeli
mysql> insert into pembeli values('01','FERI','jakarta',’ak01’);
mysql> insert into pembeli values('02','asep','depok',’bk01’);
mysql> insert into pembeli values('03','andi','depok',’ck01’);
mysql> insert into pembeli values('04','joni','jakarta',’dk01’);
Tampilkan
tabel pembeli
mysql> select * from pembeli;
+------------+------+---------+------+
| Id_pembeli | nama | alamat | kode |
+------------+------+---------+------+
| 01 |feri | jakarta |
ak01 |
| 02 |
asep | depok | bk01 |
| 03 |
andi | depok | ck01 |
| 04 |
joni | jakarta | dk01 |
+------------+------+---------+------+
4 rows in set (0.00 sec)
Membuat
Tabel barang
mysql> create table barang(kode varchar(10),nama_barang
varchar(20), produsen varchar(20));
Memasukkan
data barang
mysql> insert into barang values('ak01','gula',’cv
sugarjaya’);
mysql> insert into barang
values('bk01','kopi','cv indomakmur');
mysql> insert into barang values('ck01','terigu','pt
pangan jaya');
mysql> insert into barang values('dk01','minyak
goreng','pt minyakku oke');
Tampilkan
tabel barang
mysql> select * from barang;
+------+---------------+-----------------+
| kode | nama_barang | produsen |
+------+---------------+-----------------+
| ak01 | gula | cv sugarjaya |
| bk01 | kopi | cv indomakmur |
| ck01 | terigu | pt pangan jaya |
| dk01 | minyak goreng | pt minyakku oke |
+------+---------------+-----------------+
4 rows in set (0.00 sec)
mysql> create table harga(nama_barang
varchar(20), quantity varchar(10),harga int(20));
Memasukkan
data harga
mysql> insert into harga values('gula','1 kg','10000');
mysql> insert into harga values('kopi','1 pcs','8000');
mysql> insert into harga values('terigu','1
kg','7000');
mysql> insert into harga values('minyak
goreng','2 kg','22000');
Tampilkan
tabel harga
mysql> select * from harga;
+---------------+----------+-------+
| nama_barang
| quantity | harga |
+---------------+----------+-------+
| gula
| 1 Kg | 10000 |
| kopi
| 1 pcs | 8000 |
| terigu
| 1 kg | 7000 |
| minyak goreng | 2 kg | 22000 |
+---------------+----------+-------+
4 rows in set (0.00 sec)
Membuat
Tabel transaksi
mysql> create table transaksi(tanggal date, kode
varchar(10), total_harga int(20));
Memasukkan
data transaksi
mysql> insert into transaksi values('2010-06-20',
'ak01','20000');
mysql> insert into transaksi values('2005-06-20',
'bk01','30000');
mysql> insert into transaksi values('2005-10-20',
'ck01','15000');
mysql> insert into transaksi values('2012-10-06',
'dk01','44000');
Tampilkan
tabel transaksi
mysql> select * from transaksi;
+------------+------+-------------+
| tanggal |
kode | total_harga |
+------------+------+-------------+
| 2010-06-20 | ak01 | 20000 |
| 2005-06-20 | bk01 | 30000 |
| 2005-10-20 | ck01 | 15000 |
| 2012-10-06 | dk01 | 44000 |
+------------+------+-------------+
4 rows in set (0.00 sec)
Menggabung
2 tabel
mysql> select pembeli.Id_pembeli, pembeli.nama,
barang.nama_barang from pembeli,barang where pembeli.kode = barang.kode;
+------------+------+---------------+
| Id_pembeli | nama | nama_barang |
+------------+------+---------------+
| 01 | feri | gula |
| 02 |
asep | kopi |
| 03 |
andi | terigu |
| 04 |
joni | minyak goreng |
+------------+------+---------------+
4 rows in set (0.01 sec)
Menggabung
3 tabel
mysql> select pembeli.Id_pembeli, pembeli.nama,
barang.nama_barang, harga.harga from pembeli,barang,harga where pembeli.kode =
barang.kode AND barang.nama_barang = harga.nama_barang;
+------------+------+---------------+-------+
| Id_pembeli | nama | nama_barang | harga |
+------------+------+---------------+-------+
| 01 | feri | gula | 10000 |
| 02 |
asep | kopi | 8000 |
| 03 |
andi | terigu | 7000 |
| 04 |
joni | minyak goreng | 22000 |
+------------+------+---------------+-------+
4 rows in set (0.00 sec)
Menggabung
4 tabel
mysql> select pembeli.Id_pembeli, pembeli.nama,
barang.nama_barang, harga.harga, transaksi.tanggal, transaksi.total_harga from
pembeli,barang,harga,transaksi
where pembeli.kode = transaksi.kode AND transaksi.kode=barang.kode
AND barang.nama_barang = harga.nama_barang;
http://pribadiferi.blogspot.com/
http://pribadiferi.blogspot.com/
Tidak ada komentar:
Posting Komentar