Jumat, 16 Maret 2018

Query Tabel MySQL (Tugas 4 Manajemen dan Administrasi Basis Data)

TUGAS 4 MANAJEMEN DAN ADMINISTRASI BASIS DATA

Dosen Pengampu: Bp. Eko Purwanto




                                                        NAMA : Eko Pranoto Saputro

                                                        NIM     : 160101237

                                                        Smt      : 4 (empat) 



STMIK DUTA BANGSA SURAKARTA
2018

========================================================================

Hasil Koding:
mysql> use ekopranotosaputro;
Database changed
mysql> create table anggota
(id varchar(3) primary key,Nama varchar(50),alamat varchar(50),gaji int(7));
Query OK, 0 rows affected

mysql> desc anggota;
+--------+-------------+------+-----+---------+-------+
| Field  | Type        | Null | Key | Default | Extra |
+--------+-------------+------+-----+---------+-------+
| id     | varchar(3)  | NO   | PRI | NULL    |       |
| Nama   | varchar(50) | YES  |     | NULL    |       |
| alamat | varchar(50) | YES  |     | NULL    |       |
| gaji   | int(7)      | YES  |     | NULL    |       |
+--------+-------------+------+-----+---------+-------+
4 rows in set

mysql> insert into anggota(id,nama,alamat,gaji) values 
('100','Arif','Surabaya','10000'),
('101','Andi','Jakarta','14000'),
('102','Burhan','Malang','12000'),
('103','Fikri','Madiun','15000'),
('104','Fariz','Malang','17000'),
('105','Sigit','Surabaya','20000'),
('106','Ifan','Kediri','16000'),
('107','Hanif','Yogyakarta','12000'),('108','Zakiudin','Surabaya','21000');
Query OK, 9 rows affected
Records: 9  Duplicates: 0  Warnings: 0

mysql> select * from anggota;
+-----+----------+------------+-------+
| id  | Nama     | alamat     | gaji  |
+-----+----------+------------+-------+
| 100 | Arif     | Surabaya   | 10000 |
| 101 | Andi     | Jakarta    | 14000 |
| 102 | Burhan   | Malang     | 12000 |
| 103 | Fikri    | Madiun     | 15000 |
| 104 | Fariz    | Malang     | 17000 |
| 105 | Sigit    | Surabaya   | 20000 |
| 106 | Ifan     | Kediri     | 16000 |
| 107 | Hanif    | Yogyakarta | 12000 |
| 108 | Zakiudin | Surabaya   | 21000 |
+-----+----------+------------+-------+
9 rows in set

mysql> select count(*) from anggota;
+----------+
| count(*) |
+----------+
|        9 |
+----------+
1 row in set

mysql> select sum(gaji) from anggota;
+-----------+
| sum(gaji) |
+-----------+
| 137000    |
+-----------+
1 row in set

mysql> select max(gaji),min(gaji) from anggota;
+-----------+-----------+
| max(gaji) | min(gaji) |
+-----------+-----------+
|     21000 |     10000 |
+-----------+-----------+
1 row in set

mysql> select * from anggota where nama like '__r%';
+-----+--------+--------+-------+
| id  | Nama   | alamat | gaji  |
+-----+--------+--------+-------+
| 102 | Burhan | Malang | 12000 |
| 104 | Fariz  | Malang | 17000 |
+-----+--------+--------+-------+
2 rows in set

mysql> select sum(gaji) from anggota where alamat='Surabaya';
+-----------+
| sum(gaji) |
+-----------+
| 51000     |
+-----------+
1 row in set

mysql> select max(gaji) from anggota where alamat='Surabaya';
+-----------+
| max(gaji) |
+-----------+
|     21000 |
+-----------+
1 row in set

mysql> select count(id) from anggota where gaji between '17000' and '25000';
+-----------+
| count(id) |
+-----------+
|         3 |
+-----------+
1 row in set

mysql> select sum(gaji) from anggota where nama like '__r%';
+-----------+
| sum(gaji) |
+-----------+
| 29000     |
+-----------+
1 row in set



Tidak ada komentar:

Posting Komentar