MY SQL
TUGAS MANAJEMEN BASIS DATA
QUERY DI MY SQL
Disusun Oleh :
INGGIT NADYA NASTITI
160101243
STMIK DUTA BANGSA SURAKARTA
2018
SOAL
1. Buatlah kembali tabel karyawan dengan field yang terdiri dari :
2. Ubahlah nama field nopeg menjadi noid!
3. Ubahlah field jeniskelamin menjadi jenkel dengan type char(1)!
4. Tampilkanlah struktur tabel karyawan setelah melakukan perubahan!
5. Ubahlah nama tabel karyawan menjadi tabel pegawai!
6. Tampilkanlah tabel tersebut!
7. Tambahkan data record dengan data sebagai berikut :
8. Tampilkanlah seluruh data pegawai!
9. Tampilkan nama dan jenis kelamin dari seluruh record pada tabel pegawai!
10. Tampilkan nama dan jenis kelamin tetapi hanya jenis kelamin perempuan!
11. Tampilkan seluruh record dengan diurutkan berdasarkan nama secara ascending!
12. Tampilkan seluruh record dengan diurutkan berdasarkan kota secara ascending!
13. Tampilkan seluruh record dengan diurutkan berdasarkan tanggal lahir secara ascending!
14. Tampilkan seluruh record dengan diurutkan berdasarkan nama secara Descending!
15. Tambahkanlah field gaji dengan type integer panjang field 12.
16. Tampilkanlah struktur tabel!
17. Tampilkan seluruh record!
18. Masukkanlah gaji untuk karyawan yang memilik noid=1 dengan 1000000.
19. Tampilkanlah karyawan dengan noid=1
20. Masukkanlah gaji sesuai dengan noid sebagai berikut :
21. Tampilkanlah seluruh record pegawai!
Sebelum anda melanjutkan soal dibawah ini, tambahkanlah beberapa record sehingga dapat digunakan untuk soal berikutnya!
22. Tampilkanlah record nama, jenis kelamin, tgl lahir yang tgl lahirnya lebih kecil dari 1 januari 1980 dan urutkan berdasarkan nama!
23. Tampilkanlah record nama, jenis kelamin, tgl lahir yang tgl lahirnya lebih kecil dari
1 januari 1980 dan jenis kelamin L serta diurutkan berdasarkan nama!
24. Tampilkanlah record nama, jenis kelamin, tgl lahir yang tgl lahirnya lebih besar atau sama dengan 1 Januari 1980 dan lebih kecil atau sama dengan dari 31 Des 1985 serta diurutkan berdasarkan nama!
25. Tampilkanlah record nama, jenis kelamin, tgl lahir yang tgl lahirnya lebih besar atau sama dengan 1 Januari 1980 dan lebih kecil atau sama dengan dari 31 Des 1985 dan jenis kelamin L serta diurutkan berdasarkan nama!
26. Tampilkanlah seluruh pegawai dengan usianya saat ini!
27. Tampilkan pegawai yang usianya sama dengan atau dibawah 25 tahun!
28. Tampilkanlah pegawai yang kota kelahirannya Bandung!
29. Tampilkan pegawai yang kota kelahirannya bukan Bandung!
30. Tampilkanlah pegawai yang kota kelahirannya bukan Bandung, bukan Jakarta dan bukan Bekasi, serta diurutkan berdasarkan kota!
31. Tampilkanlah pegawai yang kota kelahirannya bukan Bandung, bukan Jakarta dan bukan Bekasi, serta diurutkan berdasarkan kota dan nama!
32. Tampilkanlah pegawai yang gajinya diantara Rp 1.500.000 dan Rp 2.500.000, record diurutkan berdasarkan gaji dan nama!
33. Berapa pegawai yang gajinya dibawah Rp. 2000.000
34. Berapa rata-rata gaji pegawai!
35. Berapa gaji terbesar!
36. Berapa gaji terkecil!
37. Berapa jumlah gaji seluruh pegawai!
38. Tampilkan pegawai dengan nama dimulai huruf a!
39.Tampilkan noid, nama yang diawali dengan huruf d!
Tampilkan noid, nama yang diakhiri dengan huruf i!
40. Tampilkan noid, nama yang berakhiran wati!
41.Tampilkan noid, nama yang mengandung huruf atau kata lia!
JAWAB
mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | cdcol | | mysql | | performance_schema | | phpmyadmin | | test | | webauth | +--------------------+ 7 rows in set mysql> create database Latihan_mysql; Query OK, 1 row affected mysql> show databases; +--------------------+ | Database | +--------------------+ | information_schema | | cdcol | | latihan_mysql | | mysql | | performance_schema | | phpmyadmin | | test | | webauth | +--------------------+ 8 rows in set mysql> use latihan_mysql; Database changed //1 mysql> create table karyawan ( -> Nopeg int(10) primary key auto_increment, -> Nama varchar (25), -> Jenis_kelamin char(2), -> Kota varchar (25), -> Kode_pos char(5), -> Tanggal_lahir date); Query OK, 0 rows affected //2 mysql> alter table karyawan change nopeg noid int (2) auto_increment; Query OK, 0 rows affected Records: 0 Duplicates: 0 Warnings: 0 //3 mysql> alter table karyawan change jenis_kelamin Jenkel char (1); Query OK, 0 rows affected Records: 0 Duplicates: 0 Warnings: 0 //4 mysql> desc karyawan; +---------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+----------------+ | noid | int(2) | NO | PRI | NULL | auto_increment | | Nama | varchar(25) | YES | | NULL | | | Jenkel | char(1) | YES | | NULL | | | Kota | varchar(25) | YES | | NULL | | | Kode_pos | char(5) | YES | | NULL | | | Tanggal_lahir | date | YES | | NULL | | +---------------+-------------+------+-----+---------+----------------+ 6 rows in set //5 mysql> alter table karyawan rename pegawai; Query OK, 0 rows affected //6 mysql> desc pegawai; +---------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+----------------+ | noid | int(2) | NO | PRI | NULL | auto_increment | | Nama | varchar(25) | YES | | NULL | | | Jenkel | char(1) | YES | | NULL | | | Kota | varchar(25) | YES | | NULL | | | Kode_pos | char(5) | YES | | NULL | | | Tanggal_lahir | date | YES | | NULL | | +---------------+-------------+------+-----+---------+----------------+ 6 rows in set //7 mysql> insert into pegawai (Nama,Jenkel,Kota,Kode_pos,Tanggal_lahir) -> values -> ('Ahmad Sobari','L','Bandung','41011','1977-10-02'), -> ('Sundariwati','P','Bandung','20123','1978-11-12'), -> ('Ryan Hendrawan','L','Jakarta','1211','1981-03-21'), -> ('Zulkarman','L','Bekasi','17211','1978-08-10'), -> ('Yuliawati','P','Bogor','0000','1982-06-9'), -> ('Mawar','P','Bogor','12345','1985-06-7'); Query OK, 6 rows affected Records: 6 Duplicates: 0 Warnings: 0 //8 mysql> select*from pegawai; +------+----------------+--------+---------+----------+---------------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | +------+----------------+--------+---------+----------+---------------+ | 1 | Ahmad Sobari | L | Bandung | 41011 | 1977-10-02 | | 2 | Sundariwati | P | Bandung | 20123 | 1978-11-12 | | 3 | Ryan Hendrawan | L | Jakarta | 1211 | 1981-03-21 | | 4 | Zulkarman | L | Bekasi | 17211 | 1978-08-10 | | 5 | Yuliawati | P | Bogor | 0000 | 1982-06-09 | | 6 | Mawar | P | Bogor | 12345 | 1985-06-07 | +------+----------------+--------+---------+----------+---------------+ 6 rows in set //9 mysql> select nama, jenkel from pegawai; +----------------+--------+ | nama | jenkel | +----------------+--------+ | Ahmad Sobari | L | | Sundariwati | P | | Ryan Hendrawan | L | | Zulkarman | L | | Yuliawati | P | | Mawar | P | +----------------+--------+ 6 rows in set //10 mysql> select nama, jenkel from pegawai where jenkel='P'; +-------------+--------+ | nama | jenkel | +-------------+--------+ | Sundariwati | P | | Yuliawati | P | | Mawar | P | +-------------+--------+ 3 rows in set //11 mysql> select*from pegawai order by nama ASC; +------+----------------+--------+---------+----------+---------------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | +------+----------------+--------+---------+----------+---------------+ | 1 | Ahmad Sobari | L | Bandung | 41011 | 1977-10-02 | | 6 | Mawar | P | Bogor | 12345 | 1985-06-07 | | 3 | Ryan Hendrawan | L | Jakarta | 1211 | 1981-03-21 | | 2 | Sundariwati | P | Bandung | 20123 | 1978-11-12 | | 5 | Yuliawati | P | Bogor | 0000 | 1982-06-09 | | 4 | Zulkarman | L | Bekasi | 17211 | 1978-08-10 | +------+----------------+--------+---------+----------+---------------+ 6 rows in set //12 mysql> select*from pegawai order by kota ASC; +------+----------------+--------+---------+----------+---------------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | +------+----------------+--------+---------+----------+---------------+ | 1 | Ahmad Sobari | L | Bandung | 41011 | 1977-10-02 | | 2 | Sundariwati | P | Bandung | 20123 | 1978-11-12 | | 4 | Zulkarman | L | Bekasi | 17211 | 1978-08-10 | | 5 | Yuliawati | P | Bogor | 0000 | 1982-06-09 | | 6 | Mawar | P | Bogor | 12345 | 1985-06-07 | | 3 | Ryan Hendrawan | L | Jakarta | 1211 | 1981-03-21 | +------+----------------+--------+---------+----------+---------------+ 6 rows in set //13 mysql> select*from pegawai order by tanggal_lahir ASC; +------+----------------+--------+---------+----------+---------------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | +------+----------------+--------+---------+----------+---------------+ | 1 | Ahmad Sobari | L | Bandung | 41011 | 1977-10-02 | | 4 | Zulkarman | L | Bekasi | 17211 | 1978-08-10 | | 2 | Sundariwati | P | Bandung | 20123 | 1978-11-12 | | 3 | Ryan Hendrawan | L | Jakarta | 1211 | 1981-03-21 | | 5 | Yuliawati | P | Bogor | 0000 | 1982-06-09 | | 6 | Mawar | P | Bogor | 12345 | 1985-06-07 | +------+----------------+--------+---------+----------+---------------+ 6 rows in set //14 mysql> select*from pegawai order by nama DESC; +------+----------------+--------+---------+----------+---------------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | +------+----------------+--------+---------+----------+---------------+ | 4 | Zulkarman | L | Bekasi | 17211 | 1978-08-10 | | 5 | Yuliawati | P | Bogor | 0000 | 1982-06-09 | | 2 | Sundariwati | P | Bandung | 20123 | 1978-11-12 | | 3 | Ryan Hendrawan | L | Jakarta | 1211 | 1981-03-21 | | 6 | Mawar | P | Bogor | 12345 | 1985-06-07 | | 1 | Ahmad Sobari | L | Bandung | 41011 | 1977-10-02 | +------+----------------+--------+---------+----------+---------------+ 6 rows in set //15 mysql> alter table pegawai add Gaji int (12); Query OK, 0 rows affected Records: 0 Duplicates: 0 Warnings: 0 //16 mysql> desc pegawai; +---------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +---------------+-------------+------+-----+---------+----------------+ | noid | int(2) | NO | PRI | NULL | auto_increment | | Nama | varchar(25) | YES | | NULL | | | Jenkel | char(1) | YES | | NULL | | | Kota | varchar(25) | YES | | NULL | | | Kode_pos | char(5) | YES | | NULL | | | Tanggal_lahir | date | YES | | NULL | | | Gaji | int(12) | YES | | NULL | | +---------------+-------------+------+-----+---------+----------------+ 7 rows in set //17 mysql> select*from pegawai; +------+----------------+--------+---------+----------+---------------+------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | Gaji | +------+----------------+--------+---------+----------+---------------+------+ | 1 | Ahmad Sobari | L | Bandung | 41011 | 1977-10-02 | NULL | | 2 | Sundariwati | P | Bandung | 20123 | 1978-11-12 | NULL | | 3 | Ryan Hendrawan | L | Jakarta | 1211 | 1981-03-21 | NULL | | 4 | Zulkarman | L | Bekasi | 17211 | 1978-08-10 | NULL | | 5 | Yuliawati | P | Bogor | 0000 | 1982-06-09 | NULL | | 6 | Mawar | P | Bogor | 12345 | 1985-06-07 | NULL | +------+----------------+--------+---------+----------+---------------+------+ 6 rows in set //18 mysql> update pegawai set gaji='1000000' where noid='1'; Query OK, 1 row affected Rows matched: 1 Changed: 1 Warnings: 0 //19 mysql> select*from pegawai limit 0,1; +------+--------------+--------+---------+----------+---------------+---------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | Gaji | +------+--------------+--------+---------+----------+---------------+---------+ | 1 | Ahmad Sobari | L | Bandung | 41011 | 1977-10-02 | 1000000 | +------+--------------+--------+---------+----------+---------------+---------+ 1 row in set //20 mysql> update pegawai set gaji='1250000' where noid='2'; Query OK, 1 row affected Rows matched: 1 Changed: 1 Warnings: 0 mysql> update pegawai set gaji='1500000' where noid='3'; Query OK, 1 row affected Rows matched: 1 Changed: 1 Warnings: 0 mysql> update pegawai set gaji='1750000' where noid='4'; Query OK, 1 row affected Rows matched: 1 Changed: 1 Warnings: 0 mysql> update pegawai set gaji='2000000' where noid='5'; Query OK, 1 row affected Rows matched: 1 Changed: 1 Warnings: 0 mysql> update pegawai set gaji='2250000' where noid='6'; Query OK, 1 row affected Rows matched: 1 Changed: 1 Warnings: 0 //21 mysql> select*from pegawai; +------+----------------+--------+---------+----------+---------------+---------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | Gaji | +------+----------------+--------+---------+----------+---------------+---------+ | 1 | Ahmad Sobari | L | Bandung | 41011 | 1977-10-02 | 1000000 | | 2 | Sundariwati | P | Bandung | 20123 | 1978-11-12 | 1250000 | | 3 | Ryan Hendrawan | L | Jakarta | 1211 | 1981-03-21 | 1500000 | | 4 | Zulkarman | L | Bekasi | 17211 | 1978-08-10 | 1750000 | | 5 | Yuliawati | P | Bogor | 0000 | 1982-06-09 | 2000000 | | 6 | Mawar | P | Bogor | 12345 | 1985-06-07 | 2250000 | +------+----------------+--------+---------+----------+---------------+---------+ 6 rows in set mysql> insert into pegawai (Nama,Jenkel,Kota,Kode_pos,Tanggal_lahir,Gaji) -> values -> ('Sobari','L','Jakarta','41011','1976-10-02','1100000'), -> ('Melia','P','Bandung','40123','1979-11-12','1200000'), -> ('Zanda Cute','L','Jakarta','12111','1980-03-21','1300000'), -> ('Maman','L','Bekasi','17211','1977-08-10','1400000'), -> ('Yenny','P','Bogor','00000','1985-06-09','1150000'), -> ('Rossa','P','Jakarta','12345','1987-07-07','1350000'), -> ('Dadan','L','Bandung','41011','1975-10-02','1450000'), -> ('Wawan','L','Semarang','40123','1971-11-12','1600000'), -> ('The Cute','L','Jakarta','12111','1977-03-21','1700000'); Query OK, 9 rows affected Records: 9 Duplicates: 0 Warnings: 0 mysql> select*from pegawai; +------+----------------+--------+----------+----------+---------------+---------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | Gaji | +------+----------------+--------+----------+----------+---------------+---------+ | 1 | Ahmad Sobari | L | Bandung | 41011 | 1977-10-02 | 1000000 | | 2 | Sundariwati | P | Bandung | 20123 | 1978-11-12 | 1250000 | | 3 | Ryan Hendrawan | L | Jakarta | 1211 | 1981-03-21 | 1500000 | | 4 | Zulkarman | L | Bekasi | 17211 | 1978-08-10 | 1750000 | | 5 | Yuliawati | P | Bogor | 0000 | 1982-06-09 | 2000000 | | 6 | Mawar | P | Bogor | 12345 | 1985-06-07 | 2250000 | | 7 | Sobari | L | Jakarta | 41011 | 1976-10-02 | 1100000 | | 8 | Melia | P | Bandung | 40123 | 1979-11-12 | 1200000 | | 9 | Zanda Cute | L | Jakarta | 12111 | 1980-03-21 | 1300000 | | 10 | Maman | L | Bekasi | 17211 | 1977-08-10 | 1400000 | | 11 | Yenny | P | Bogor | 00000 | 1985-06-09 | 1150000 | | 12 | Rossa | P | Jakarta | 12345 | 1987-07-07 | 1350000 | | 13 | Dadan | L | Bandung | 41011 | 1975-10-02 | 1450000 | | 14 | Wawan | L | Semarang | 40123 | 1971-11-12 | 1600000 | | 15 | The Cute | L | Jakarta | 12111 | 1977-03-21 | 1700000 | +------+----------------+--------+----------+----------+---------------+---------+ 15 rows in set //22 mysql> select nama, jenkel,tanggal_lahir from pegawai where tanggal_lahir<'1980-01-01' order by nama asc; +--------------+--------+---------------+ | nama | jenkel | tanggal_lahir | +--------------+--------+---------------+ | Ahmad Sobari | L | 1977-10-02 | | Dadan | L | 1975-10-02 | | Maman | L | 1977-08-10 | | Melia | P | 1979-11-12 | | Sobari | L | 1976-10-02 | | Sundariwati | P | 1978-11-12 | | The Cute | L | 1977-03-21 | | Wawan | L | 1971-11-12 | | Zulkarman | L | 1978-08-10 | +--------------+--------+---------------+ 9 rows in set //23 mysql> select nama, jenkel,tanggal_lahir from pegawai where tanggal_lahir<'1980-01-01' and jenkel='L' order by nama asc; +--------------+--------+---------------+ | nama | jenkel | tanggal_lahir | +--------------+--------+---------------+ | Ahmad Sobari | L | 1977-10-02 | | Dadan | L | 1975-10-02 | | Maman | L | 1977-08-10 | | Sobari | L | 1976-10-02 | | The Cute | L | 1977-03-21 | | Wawan | L | 1971-11-12 | | Zulkarman | L | 1978-08-10 | +--------------+--------+---------------+ 7 rows in set //24 mysql> select nama, jenkel,tanggal_lahir from pegawai where tanggal_lahir>='1980-01-01' and tanggal_lahir<='1985-12-31' order by nama asc; +----------------+--------+---------------+ | nama | jenkel | tanggal_lahir | +----------------+--------+---------------+ | Mawar | P | 1985-06-07 | | Ryan Hendrawan | L | 1981-03-21 | | Yenny | P | 1985-06-09 | | Yuliawati | P | 1982-06-09 | | Zanda Cute | L | 1980-03-21 | +----------------+--------+---------------+ 5 rows in set //25 mysql> select nama, jenkel,tanggal_lahir from pegawai where tanggal_lahir>='1980-01-01' and tanggal_lahir<='1985-12-31' and jenkel='L' order by nama asc; +----------------+--------+---------------+ | nama | jenkel | tanggal_lahir | +----------------+--------+---------------+ | Ryan Hendrawan | L | 1981-03-21 | | Zanda Cute | L | 1980-03-21 | +----------------+--------+---------------+ 2 rows in set //26 mysql> select*,year(curdate())-year(tanggal_lahir)as umur from pegawai; +------+----------------+--------+----------+----------+---------------+---------+------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | Gaji | umur | +------+----------------+--------+----------+----------+---------------+---------+------+ | 1 | Ahmad Sobari | L | Bandung | 41011 | 1977-10-02 | 1000000 | 41 | | 2 | Sundariwati | P | Bandung | 20123 | 1978-11-12 | 1250000 | 40 | | 3 | Ryan Hendrawan | L | Jakarta | 1211 | 1981-03-21 | 1500000 | 37 | | 4 | Zulkarman | L | Bekasi | 17211 | 1978-08-10 | 1750000 | 40 | | 5 | Yuliawati | P | Bogor | 0000 | 1982-06-09 | 2000000 | 36 | | 6 | Mawar | P | Bogor | 12345 | 1985-06-07 | 2250000 | 33 | | 7 | Sobari | L | Jakarta | 41011 | 1976-10-02 | 1100000 | 42 | | 8 | Melia | P | Bandung | 40123 | 1979-11-12 | 1200000 | 39 | | 9 | Zanda Cute | L | Jakarta | 12111 | 1980-03-21 | 1300000 | 38 | | 10 | Maman | L | Bekasi | 17211 | 1977-08-10 | 1400000 | 41 | | 11 | Yenny | P | Bogor | 00000 | 1985-06-09 | 1150000 | 33 | | 12 | Rossa | P | Jakarta | 12345 | 1987-07-07 | 1350000 | 31 | | 13 | Dadan | L | Bandung | 41011 | 1975-10-02 | 1450000 | 43 | | 14 | Wawan | L | Semarang | 40123 | 1971-11-12 | 1600000 | 47 | | 15 | The Cute | L | Jakarta | 12111 | 1977-03-21 | 1700000 | 41 | +------+----------------+--------+----------+----------+---------------+---------+------+ 15 rows in set //27 mysql> select*from pegawai where year(curdate())-year(tanggal_lahir)<=25; Empty set //28 mysql> select*from pegawai where kota='Bandung'; +------+--------------+--------+---------+----------+---------------+---------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | Gaji | +------+--------------+--------+---------+----------+---------------+---------+ | 1 | Ahmad Sobari | L | Bandung | 41011 | 1977-10-02 | 1000000 | | 2 | Sundariwati | P | Bandung | 20123 | 1978-11-12 | 1250000 | | 8 | Melia | P | Bandung | 40123 | 1979-11-12 | 1200000 | | 13 | Dadan | L | Bandung | 41011 | 1975-10-02 | 1450000 | +------+--------------+--------+---------+----------+---------------+---------+ 4 rows in set //29 mysql> select*from pegawai where kota!='Bandung'; +------+----------------+--------+----------+----------+---------------+---------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | Gaji | +------+----------------+--------+----------+----------+---------------+---------+ | 3 | Ryan Hendrawan | L | Jakarta | 1211 | 1981-03-21 | 1500000 | | 4 | Zulkarman | L | Bekasi | 17211 | 1978-08-10 | 1750000 | | 5 | Yuliawati | P | Bogor | 0000 | 1982-06-09 | 2000000 | | 6 | Mawar | P | Bogor | 12345 | 1985-06-07 | 2250000 | | 7 | Sobari | L | Jakarta | 41011 | 1976-10-02 | 1100000 | | 9 | Zanda Cute | L | Jakarta | 12111 | 1980-03-21 | 1300000 | | 10 | Maman | L | Bekasi | 17211 | 1977-08-10 | 1400000 | | 11 | Yenny | P | Bogor | 00000 | 1985-06-09 | 1150000 | | 12 | Rossa | P | Jakarta | 12345 | 1987-07-07 | 1350000 | | 14 | Wawan | L | Semarang | 40123 | 1971-11-12 | 1600000 | | 15 | The Cute | L | Jakarta | 12111 | 1977-03-21 | 1700000 | +------+----------------+--------+----------+----------+---------------+---------+ 11 rows in set //30 mysql> select*from pegawai where kota!='Bandung' and kota!='Jakarta' and kota!='Bekasi' order by kota; +------+-----------+--------+----------+----------+---------------+---------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | Gaji | +------+-----------+--------+----------+----------+---------------+---------+ | 5 | Yuliawati | P | Bogor | 0000 | 1982-06-09 | 2000000 | | 6 | Mawar | P | Bogor | 12345 | 1985-06-07 | 2250000 | | 11 | Yenny | P | Bogor | 00000 | 1985-06-09 | 1150000 | | 14 | Wawan | L | Semarang | 40123 | 1971-11-12 | 1600000 | +------+-----------+--------+----------+----------+---------------+---------+ 4 rows in set //31 mysql> select*from pegawai where kota!='Bandung' and kota!='Jakarta' and kota!='Bekasi' order by kota and nama; +------+-----------+--------+----------+----------+---------------+---------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | Gaji | +------+-----------+--------+----------+----------+---------------+---------+ | 5 | Yuliawati | P | Bogor | 0000 | 1982-06-09 | 2000000 | | 6 | Mawar | P | Bogor | 12345 | 1985-06-07 | 2250000 | | 11 | Yenny | P | Bogor | 00000 | 1985-06-09 | 1150000 | | 14 | Wawan | L | Semarang | 40123 | 1971-11-12 | 1600000 | +------+-----------+--------+----------+----------+---------------+---------+ 4 rows in set //32 mysql> select*from pegawai where gaji between 1500000 and 2500000 order by gaji and nama; +------+----------------+--------+----------+----------+---------------+---------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | Gaji | +------+----------------+--------+----------+----------+---------------+---------+ | 3 | Ryan Hendrawan | L | Jakarta | 1211 | 1981-03-21 | 1500000 | | 4 | Zulkarman | L | Bekasi | 17211 | 1978-08-10 | 1750000 | | 5 | Yuliawati | P | Bogor | 0000 | 1982-06-09 | 2000000 | | 6 | Mawar | P | Bogor | 12345 | 1985-06-07 | 2250000 | | 14 | Wawan | L | Semarang | 40123 | 1971-11-12 | 1600000 | | 15 | The Cute | L | Jakarta | 12111 | 1977-03-21 | 1700000 | +------+----------------+--------+----------+----------+---------------+---------+ 6 rows in set //33 mysql> select count(gaji) from pegawai where gaji<2000000 13="" 1="" count="" gaji="" in="" mysql="" row="" set=""> select avg(gaji) from pegawai; +--------------+ | avg(gaji) | +--------------+ | 1466666.6667 | +--------------+ 1 row in set //35 mysql> select max(gaji) from pegawai; +-----------+ | max(gaji) | +-----------+ | 2250000 | +-----------+ 1 row in set //36 mysql> select min(gaji) from pegawai; +-----------+ | min(gaji) | +-----------+ | 1000000 | +-----------+ 1 row in set //37 mysql> select sum(gaji) from pegawai; +-----------+ | sum(gaji) | +-----------+ | 22000000 | +-----------+ 1 row in set //38 mysql> select*from pegawai where nama like 'a%'; +------+--------------+--------+---------+----------+---------------+---------+ | noid | Nama | Jenkel | Kota | Kode_pos | Tanggal_lahir | Gaji | +------+--------------+--------+---------+----------+---------------+---------+ | 1 | Ahmad Sobari | L | Bandung | 41011 | 1977-10-02 | 1000000 | +------+--------------+--------+---------+----------+---------------+---------+ 1 row in set //39 mysql> select noid from pegawai where nama like 'd%'; +------+ | noid | +------+ | 13 | +------+ 1 row in set mysql> select noid, nama from pegawai where nama like '%i'; +------+--------------+ | noid | nama | +------+--------------+ | 1 | Ahmad Sobari | | 2 | Sundariwati | | 5 | Yuliawati | | 7 | Sobari | +------+--------------+ 4 rows in set mysql> select noid from pegawai where nama like '%i'; +------+ | noid | +------+ | 1 | | 2 | | 5 | | 7 | +------+ 4 rows in set //40 mysql> select noid, nama from pegawai where nama like '%wati'; +------+-------------+ | noid | nama | +------+-------------+ | 2 | Sundariwati | | 5 | Yuliawati | +------+-------------+ 2 rows in set mysql> select noid from pegawai where nama like '%wati'; +------+ | noid | +------+ | 2 | | 5 | +------+ 2 rows in set //41 mysql> select noid from pegawai where nama like '%lia'; +------+ | noid | +------+ | 8 | +------+ 1 row in set 2000000>
Komentar
Posting Komentar