0% found this document useful (0 votes)
40 views3 pages

Merelasikan Tabel: Create Table Gaji (Gol Char (1) Primary Key Not Null, Gaji Int (8) )

The document shows SQL commands used to create two tables - a GAJI table to store employee grade and salary information, and a PEGAWAI table to store employee names and grades. Various JOIN queries are performed between the two tables to return matching rows and aggregate salary data with employee names and grades. Conditional logic is also demonstrated using IF statements to return bonus amounts corresponding to each grade.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views3 pages

Merelasikan Tabel: Create Table Gaji (Gol Char (1) Primary Key Not Null, Gaji Int (8) )

The document shows SQL commands used to create two tables - a GAJI table to store employee grade and salary information, and a PEGAWAI table to store employee names and grades. Various JOIN queries are performed between the two tables to return matching rows and aggregate salary data with employee names and grades. Conditional logic is also demonstrated using IF statements to return bonus amounts corresponding to each grade.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

MERELASIKAN TABEL

CREATE DATABASE koneksi;


USE koneksi;
mysql> CREATE TABLE GAJI(GOL CHAR(1) PRIMARY KEY NOT NULL,GAJI INT(8));
mysql> INSERT INTO GAJI VALUES('A',1500000);
mysql> INSERT INTO GAJI VALUES('B',1250000);
mysql> INSERT INTO GAJI VALUES('C',1000000);
mysql> SELECT * FROM GAJI;
+-----+---------+
| GOL | GAJI |
+-----+---------+
| A | 1500000 |
| B | 1250000 |
| C | 1000000 |
+-----+---------+
mysql> CREATE TABLE PEGAWAI(NAMA VARCHAR(20),GOL CHAR(1));
mysql> INSERT INTO PEGAWAI VALUES('HENDRI','A');
mysql> INSERT INTO PEGAWAI VALUES('SENO','B');
mysql> INSERT INTO PEGAWAI VALUES('BUDI','D');
mysql> INSERT INTO PEGAWAI VALUES('SITI','E');
mysql> SELECT * FROM PEGAWAI;
+--------+------+
| NAMA | GOL |
+--------+------+
| HENDRI | A |
| SENO | B |
| BUDI | D |
| SITI | E |
+--------+------+

mysql> SELECT * FROM PEGAWAI INNER JOIN GAJI


ON PEGAWAI.GOL=GAJI.GOL;
+--------+------+-----+---------+
| NAMA | GOL | GOL | GAJI |
+--------+------+-----+---------+
| HENDRI | A | A | 1500000 |
| SENO | B | B | 1250000 |
+--------+------+-----+---------+

mysql> SELECT * FROM PEGAWAI LEFT JOIN GAJI


ON PEGAWAI.GOL=GAJI.GOL;
+--------+------+------+---------+
| NAMA | GOL | GOL | GAJI |
+--------+------+------+---------+
| HENDRI | A | A | 1500000 |
| SENO | B | B | 1250000 |
| BUDI | D | NULL | NULL |
| SITI | E | NULL | NULL |
+--------+------+------+---------+

mysql> SELECT * FROM PEGAWAI RIGHT JOIN GAJI


ON PEGAWAI.GOL=GAJI.GOL;
+--------+------+-----+---------+
| NAMA | GOL | GOL | GAJI |
+--------+------+-----+---------+
| HENDRI | A | A | 1500000 |
| SENO | B | B | 1250000 |
| NULL | NULL | C | 1000000 |
+--------+------+-----+---------+

mysql> SELECT NAMA,PEGAWAI.GOL,GAJI


FROM PEGAWAI INNER JOIN GAJI ON PEGAWAI.GOL=GAJI.GOL;

+--------+------+---------+
| NAMA | GOL | GAJI |
+--------+------+---------+
| HENDRI | A | 1500000 |
| SENO | B | 1250000 |
+--------+------+---------+

mysql> SELECT PEGAWAI.NAMA,PEGAWAI.GOL,GAJI.GAJI


FROM PEGAWAI LEFT JOIN GAJI ON PEGAWAI.GOL=GAJI.GOL;
+--------+------+---------+
| NAMA | GOL | GAJI |
+--------+------+---------+
| HENDRI | A | 1500000 |
| SENO | B | 1250000 |
| BUDI | D | NULL |
| SITI | E | NULL |
+--------+------+---------+

mysql> SELECT PEGAWAI.NAMA,PEGAWAI.GOL,GAJI.GAJI


FROM PEGAWAI RIGHT JOIN GAJI ON PEGAWAI.GOL=GAJI.GOL;
+--------+------+---------+
| NAMA | GOL | GAJI |
+--------+------+---------+
| HENDRI | A | 1500000 |
| SENO | B | 1250000 |
| NULL | NULL | 1000000 |
+--------+------+---------+

mysql>SELECT PEGAWAI.NAMA,PEGAWAI.GOL,GAJI.GAJI,
IF(PEGAWAI.GOL='A', 200000,IF(PEGAWAI.GOL="B",
150000,100000))AS BONUS
FROM PEGAWAI RIGHT JOIN GAJI ON PEGAWAI.GOL=GAJI.GOL;
+--------+------+---------+--------+
| NAMA | GOL | GAJI | BONUS |
+--------+------+---------+--------+
| HENDRI | A | 1500000 | 200000 |
| SENO | B | 1250000 | 150000 |
| NULL | NULL | 1000000 | 100000 |
+--------+------+---------+--------+
3 rows in set (0.00 sec)

mysql> SELECT PEGAWAI.NAMA,PEGAWAI.GOL,GAJI.GAJI,


IF(PEGAWAI.GOL= 'A',200000,IF(PEGAWAI.GOL="B",
150000,100000))AS BONUS
FROM PEGAWAI, GAJI WHERE PEGAWAI.GOL=GAJI.GOL;
+--------+------+---------+--------+
| NAMA | GOL | GAJI | BONUS |
+--------+------+---------+--------+
| HENDRI | A | 1500000 | 200000 |
| SENO | B | 1250000 | 150000 |
+--------+------+---------+--------+
2 rows in set (0.00 sec)

Latihan :

You might also like