0% found this document useful (0 votes)
48 views

Lab 6

The document contains SQL statements to create tables, insert data, and perform queries on a restaurant database. The tables created are for employees, customers, packages, menus, and transactions. Data is inserted into these tables. Queries are written to select and aggregate data from the tables, such as counting transactions by month, finding the employee with the lowest gmail salary, and identifying employees with only one transaction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
48 views

Lab 6

The document contains SQL statements to create tables, insert data, and perform queries on a restaurant database. The tables created are for employees, customers, packages, menus, and transactions. Data is inserted into these tables. Queries are written to select and aggregate data from the tables, such as counting transactions by month, finding the employee with the lowest gmail salary, and identifying employees with only one transaction.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

cd mysql/bin

mysql -h localhost -u root

CREATE DATABASE Restoran2;

USE Restoran2;

===================================================================================
===================================================================================
==================================
NOMOR 1

CREATE TABLE employee(


ID_Employee CHAR(5) NOT NULL,
Nama_Depan VARCHAR(30) NOT NULL,
NAma_Belakang VARCHAR(30),
jabatan VARCHAR(30),
alamat VARCHAR(30)NOT NULL,
email VARCHAR(30)NOT NULL,
Nomor_Telepon VARCHAR(15)NOT NULL,
gaji INTEGER,
PRIMARY KEY(ID_Employee)
);

CREATE TABLE customer(


ID_Customer CHAR(5)NOT NULL,
Nama_Depan VARCHAR(30)NOT NULL,
Nama_Belakang VARCHAR(30),
alamat VARCHAR(30)NOT NULL,
email VARCHAR(30)NOT NULL,
Nomor_Telepon VARCHAR(15)NOT NULL,
PRIMARY KEY(ID_Customer)
);

CREATE TABLE paket(


ID_Paket CHAR(5)NOT NULL,
Harga_PAket INTEGER,
PRIMARY KEY(ID_Paket)
);

CREATE TABLE menu(


ID_Menu CHAR(5)NOT NULL,
Nama_Menu VARCHAR(30)NOT NULL,
Jenis_Menu VARCHAR(20)NOT NULL,
ID_Paket CHAR(5)NOT NULL,
PRIMARY KEY(ID_Menu),
FOREIGN KEY(ID_Paket) REFERENCES paket(ID_Paket)
)engine=InnoDB;

CREATE TABLE transaction(


ID_Customer CHAR(5)NOT NULL,
ID_Paket CHAR(5)NOT NULL,
ID_Employee CHAR(5)NOT NULL,
Transaction_Date DATE,
FOREIGN KEY(ID_Customer) REFERENCES customer(ID_Customer),
FOREIGN KEY(ID_Employee) REFERENCES employee(ID_Employee),
FOREIGN KEY(ID_Paket) REFERENCES paket(ID_Paket)
)engine=InnoDB;
===================================================================================
===================================================================================
==================================
NOMOR 2

INSERT INTO employee(ID_Employee, Nama_Depan, Nama_Belakang, jabatan, alamat,


email, Nomor_Telepon, gaji)
VALUES ('E0001', 'Sax', 'Fucelli', 'Manager', '04 Numero Quatro', '[email protected]',
'084-444-4444', '10000000'),
('E0002', 'Smitty', 'Werbenmanjensen', 'Customer Service', '01 Under Sea',
'[email protected]', '081-111-1111', '5000000'),
('E0003', 'Maximillion', 'Pegasus', 'Cashier', '18 Duelist Kingdom',
'[email protected]', '083-171-1377', '2000000'),
('E0004', 'Oktavia', 'Seckendorff', 'Chef', '70 Under World',
'[email protected]', '085-120-8753', '3000000'),
('E0005', 'Frejya', 'Wion', 'Chef', '05 Walkure Space', '[email protected]',
'088-237-6718', '3500000'),
('E0006', 'Won',' ' , 'Chef', '23 Harvest Moon', '[email protected]', '089-671-
0283', '3750000'),
('E0007', 'Barney',' ' , 'Cashier', '45 Dino Street', '[email protected]',
'087-332-9716', '2500000');

===================================================================================
===================================================================================
==================================
NOMOR 3

INSERT INTO customer(ID_Customer, Nama_Depan, Nama_Belakang, alamat, email,


Nomor_Telepon)
VALUES ('C0001', 'Santa', 'Monica', '232 Database Annex', '[email protected]',
'083-221-8762'),
('C0002', 'Sil', 'Eighty', '80 Downhill Building', '[email protected]',
'082-123-0938'),
('C0003', 'Chandra', 'Nalaar', '191 Magic Land', '[email protected]',
'089-382-8371'),
('C0004', 'Gideon', 'Zura', '202 Indes Annex', '[email protected]', '084-
829-3882'),
('C0005', 'Strygwyr',' ', '147 Bloody Annex', '[email protected]',
'081-826-2372'),
('C0006', 'Mogul', 'Kahn', '182 ex Building', '[email protected]', '085-
562-7782'),
('C0007', 'John', 'Cena', '92 Smack Land', '[email protected]', '086-829-
9283'),
('C0008', 'Budi',' ', '141 Wonder Land', '[email protected]', '087-927-
8263'),
('C0009', 'Immelman',' ', '220 Plane Building', '[email protected]',
'088-283-9372'),
('C0010', 'Datboi',' ', '31 Frog Annex', '[email protected]', '081-028-
0373');

===================================================================================
===================================================================================
==================================
NOMOR 4

INSERT INTO paket(ID_Paket, Harga_Paket)


VALUES ('P0001', '3000000'),
('P0002', '2500000'),
('P0003', '2000000');
===================================================================================
===================================================================================
==================================
NOMOR 5

INSERT INTO menu(ID_Menu, Nama_Menu, Jenis_Menu, ID_Paket)


VALUES ('M0001', 'Nasi Kecap', 'Makanan', 'P0001'),
('M0002', 'Soda Mentos', 'Minuman', 'P0002'),
('M0003', 'Es Krim Panas', 'Dessert', 'P0003'),
('M0004', 'Ayam Om', 'Makanan', 'P0002'),
('M0005', 'Teh Pedas', 'Minuman', 'P0001'),
('M0006', 'Giga Pudding', 'Dessert', 'P0002'),
('M0007', 'Nasi UMN', 'Makanan', 'P0003'),
('M0008', 'Kopi Setarbak', 'Minuman', 'P0003'),
('M0009', 'Kue Rebus', 'Dessert', 'P0001'),
('M0010', 'Gudetama', 'Dessert', 'P0001');

===================================================================================
===================================================================================
==================================
NOMOR 6

INSERT INTO transaction(ID_Customer, ID_Employee, ID_Paket, Transaction_Date)


VALUES ('C0001', 'E0002', 'P0003', '2016-02-25'),
('C0002', 'E0001', 'P0002', '2016-03-12'),
('C0003', 'E0002', 'P0002', '2016-04-10'),
('C0004', 'E0004', 'P0001', '2016-06-28'),
('C0005', 'E0001', 'P0002', '2016-03-30'),
('C0006', 'E0003', 'P0003', '2016-03-10'),
('C0007', 'E0005', 'P0001', '2016-03-01'),
('C0008', 'E0002', 'P0002', '2016-08-30'),
('C0009', 'E0002', 'P0003', '2016-11-02'),
('C0010', 'E0005', 'P0001', '2016-08-18');

===================================================================================
===================================================================================
==================================
NOMOR 7

SELECT CONCAT(Nama_Depan, ' ', Nama_Belakang) AS "Nama Customer"


FROM customer
ORDER BY Nama_Depan;

===================================================================================
===================================================================================
==================================
NOMOR 8

SELECT DATE_FORMAT(Transaction_Date,"%M") Bulan, COUNT(*) jumlah


FROM transaction
GROUP BY MONTH(Transaction_Date);

===================================================================================
===================================================================================
==================================
NOMOR 9

SELECT CONCAT(Nama_Depan, ' ', Nama_Belakang) AS Nama, gaji AS Gaji


FROM employee
WHERE email LIKE '%gmail%'
ORDER BY gaji
LIMIT 1;

===================================================================================
===================================================================================
==================================
NOMOR 10

SELECT ID_Employee AS "Kode Pekerja",


COUNT(*) AS "Banyak Transaksi",
GROUP_CONCAT(DAY (Transaction_Date),' ', MONTHNAME(Transaction_Date), ' ', YEAR
(Transaction_Date)) AS "Jadwal Transaksi"
FROM transaction
GROUP BY 1
HAVING COUNT(*) >= 1
ORDER BY COUNT(*) DESC;

===================================================================================
===================================================================================
==================================
NOMOR 11

SELECT email, COUNT(IF(email(employee) LIKE '%gmail%' OR '%google%)) google,


COUNT(IF(email(employee) LIKE '%live%')) live,
COUNT(IF(email(employee) LIKE '%yahoo%')) yahoo
FROM employee;

FROM employee
WHERE email LIKE '%gmail%' OR '%google%'
GROUP BY 1;

WHERE email LIKE '%gmail%' OR '%google%';


SELECT email,
COUNT(*) google
FROM employee
WHERE email LIKE '%live%',
SELECT email,
COUNT(*) google
FROM employee
WHERE email LIKE '%yahoo%';

SELECT email, COUNT(*)


FROM employee;

===================================================================================
===================================================================================
==================================
NOMOR 12

SELECT ID_Employee, Nama_Depan


FROM (SELECT ID_Employee
FROM transaction
GROUP BY 1
HAVING COUNT(*) = 1);
WHERE (SELECT ,
COUNT(*));

SELECT ID_Employee AS "Kode Pekerja",


COUNT(*) AS "Banyak Transaksi",
GROUP_CONCAT(DAY (Transaction_Date),' ', MONTHNAME(Transaction_Date), ' ', YEAR
(Transaction_Date)) AS "Jadwal Transaksi"
FROM TRANSACTION
GROUP BY 1
HAVING COUNT(*) >= 1
ORDER BY COUNT(*) DESC;

You might also like