You are on page 1of 31

WORKBOOK ACTIVITY

DFC 20203 DATABASE DESIGN

Lab Activity 4 : Entity Relationship Diagram


Duration: 4 Hours

Learning Outcomes
This activity encompasses activities 4A, 4B and 4C

At the end of this activity session, you should be able to:


1. Identify the basic elements of ERD.
2. Design E-R Diagram based on a given scenario by using Chen’s Model and
Crow’Foot
3. Convert a given ERD into relational tables.

Activity 4A

Activity Outcome: Identify the basic elements of ERD and design the ERD based on a given
scenario by using Chen’s Model.

Nena Electrical Co. Wishes to create a database with the following entities and attributes:
a. Customer, with attributes: CustomerID, Name, Email, Telephone
b. Location, with attributes: LocationID, Address, Type
c. Rate, with attributes: , RateID, RateClass, Rateperkwh

After the interviews with the owner you have come up with the following business rules:
● Customer can have one or more locations
● Each location can have one and only one customer
● Each location can have one or more rates
● Each rate may be used at many locations, or not used at a location

1. Identify all the basic elements of ERD that are involved based on the above scenario:
a) Entity and Attribute

Entity Attribute

b) Relationship, Connectivity and Cardinality

Page 2 of 31
DFC 2083 DATABASE DESIGN

c) Identifier keys

Entity Primary Key

2. Draw the E-R Diagram using Chen’s Model based on the Activity4A(1) that you have
identified.

Page 3 of 31
DFC 20203 DATABASE DESIGN

Activity 4B

Activity Outcome: Identify the basic elements of ERD and design the ERD based on a given
scenario by using Crow’s Foot.

An automobile insurance company needs to keep track of information about vehicle. The
company has to store information of customer, car and accident. Customer information is
LicenseNo, name and address. Customers can own one or more cars, where the car information
is PlateNo, model and year. A car not involved or involved in many accidents. If the car is involved
in an accident, the information that will be stored is Report_number, location and date.

1. Identify all the basic elements of ERD that are involved based on the above scenario:

a) Entity and Attribute

Entity Attribute

a) Relationship, Connectivity and Cardinality

b) Identifier keys

Entity Primary Key

Page 4 of 31
DFC 2083 DATABASE DESIGN

2. Draw the E-R Diagram using Chen’s Model based on the Activity4B(1) that you have
identified.

Page 5 of 31
DFC 20203 DATABASE DESIGN

Activity 4C
Activity Outcome: Convert a given ERD into relational tables.
1. Convert the E-R Diagram based on the Activity 4A(2) into the relational tables.

2. Convert the E-R Diagram based on the Activity 4B(2) into the relational tables.

Page 6 of 31
DFC 2083 DATABASE DESIGN

Activity 4D
Activity outcome : Using Chen Model Notation, Draw the ERD for the given scenario below.

There are many soccer teams in Liga Super Malaysia ; each team has an ID,name,main stadium,
and which city this team belongs.Each team has many players,and each player belongs to one
team.Each player has a number,name,DOB,start year and shirt number that he uses.Teams play
matches, for each match you need to keep track the date on which the game is played, match ID
and the final result of the match.Each match has exactly three referees.For each referee have an
referee ID,name,DOB and year of experience.
(10 Marks)

Page 7 of 31
DFC 20203 DATABASE DESIGN

Activity 4E
Activity outcome : Using Crow’s Foot Model Notation, Draw the ERD for the given scenario below.

Seremban Hospital has several wards. This hospital has a few types of ward depends on types
of patients. Patient information will be recorded into file that patient number, patient name,
address, phone number, IC number, patient and group of blood patient. Each patient is treated
by a doctor at one time but one doctor can treats a number of patients. The information of doctors
recorded are : doctor ID, doctor name, address, phone no, IC no and expertise. The nurses will
be assigned to take care of the patients. Nurses in this hospital are graded based on their
experience, qualification and duration of working in the hospital.

(10 Marks)

SET 1
Page 8 of 31
DFC 2083 DATABASE DESIGN

LAB ACTIVITY 5: Structured Query Language (SQL)


Duration : 8 Hours

Learning Outcomes
This activity encompasses of activities from 5A to 5D.

By the end of this laboratory session, you should be able to:

1. Understand and apply DDL commands


2. Understand and apply DML commands
3. Understand and apply SQL Advanced commands
4. Understand and apply SQL Functions

Hardware/ Software : MySQL

Activity 5A

Activity Outcome: Able to create Database, tables and manipulates tables using DDL
statements

Procedures

Step 1 : Create new database name COMPANY.


CREATE DATABASE COMPANY;

Step 2 : Create tables VENDOR and PRODUCT.

Step 3 : Click on SQL tab and type the SQL command(VENDOR table) as shown below.

CREATE TABLE VENDOR (


V_KOD INTEGER NOT NULL UNIQUE,
V_NAMA VARCHAR(35) NOT NULL,
V_POSKOD VARCHAR(5) NOT NULL,
V_TELEFON INTEGER NOT NULL,
PRIMARY KEY (V_KOD)
);

Step 4 : Run the SQL command.


Step 5 : Save the Query.
Step 6 : Click on SQL tab to create PRODUCT table.

Page 9 of 31
DFC 20203 DATABASE DESIGN

CREATE TABLE PRODUCT (


P_KOD VARCHAR(7) NOT NULL,
P_ITEM VARCHAR(35) NOT NULL,
P_HANTAR INTEGER(3) NOT NULL,
P_HARGA DECIMAL(8,2) NOT NULL,
V_KOD INTEGER NOT NULL,
PRIMARY KEY (P_KOD),
FOREIGN KEY (V_KOD) REFERENCES
VENDOR(V_KOD)
);

Step 7 : Type SQL command to change the P_ITEM character length from 35 to 40.

ALTER TABLE PRODUCT


MODIFY P_ITEM VARCHAR(40);

Step 8 : Type SQL command to Add attribute V_AGE into table VENDOR.

ALTER TABLE VENDOR


ADD V_AGE INT(3);

Step 9 : Type SQL command to change the data type attribute V_AGE from INT to CHAR.
ALTER TABLE VENDOR
ALTER V_AGE CHAR;

Step 10 : Type SQL command to Delete attribute V_AGE from table VENDOR.
ALTER TABLE VENDOR
DROP V_AGE;

Step 11 : Type SQL command to delete VENDOR table.

DROP TABLE VENDOR;

Page 10 of 31
DFC 2083 DATABASE DESIGN

Activity 5B

Activity Outcome: Able to manipulates tables using DDL statements

(Refer Activity 5A)

Procedures:

Step 1 : Click on SQL tab and type SQL command that insert new data into PRODUCT table .
INSERT INTO PRODUCT
VALUES ( ‘JT00833’, ‘Joystick’, 6, 30.99, 25595);

Step 2 : Type the following SQL command to insert another data into PRODUCT table.
INSERT INTO PRODUCT
VALUES ( ‘KK0011’, ‘Scanner’, 12, 300.99, 21344);

Step 3 : Click on SQL tab.

Step 4 : Type SQL command to update a data in the PRODUCT table.


UPDATE PRODUCT
SET P_HARGA = 12
WHERE P_KOD = ‘JT00833’;

Step 5 : Click on SQL tab and type SQL command to delete a data in the PRODUCT table
using the following command.

DELETE FROM PRODUCT


WHERE P_KOD=’JT00833’;

Step 6 : Click on SQL tab and type SQL command to delete a data in the PRODUCT table
using the following command.

SELECT * FROM PRODUCT;

Page 11 of 31
DFC 20203 DATABASE DESIGN

Activity 5C

Appendix B

Database : CAR

CUSTOMER

custid custname Car_number Phone_number Register_date


P0001 David Lim WKM 1234 0139845263 12/06/14
P0002 Abu Hassan DBA 8999 0126377298 23/05/14
P0003 Low Ban Huat PFL 3434 0197894563 05/01/14
P0004 Karigalan BGN 2511 0112356897 23/05/13
P0007 Kamal Ibrahim WEP1103 0145689471 12/07/14

CAR_COMPONENT

compID compName price


KK001 ISWARA Rear Lamp 100
KK002 WIRA Front Bumper 450
KK003 ISWARA Front Mirror 500
KK004 WAJA Break Lamp 250
KK005 WIRA Front Lamp 350

CLAIM

claimID claim_date custid


CL001 02/06/14 P0002
CL002 10/07/14 P0001
CL003 24/07/13 P0004
CL004 05/08/14 P0002
CL012 07/07/14 P0003

COMPONENT_CLAIM

claimID compID quantity


CL001 KK002 1
CL001 KK005 2
CL003 KK001 2
CL012 KK003 1
CL004 KK001 2
CL002 KK003 1
CL003 KK003 1

Page 12 of 31
DFC 2083 DATABASE DESIGN

Activity Outcome: Able to understand and apply SQL Advanced commands

Procedures:

Step 1 : Open any Database software.


Step 2 : Create new blank database name CAR. (Refer Appendix B)
Step 3 : Create table CUSTOMER, CAR_COMPONENT, CLAIM and
COMPONENT_CLAIM .
Step 4 : Insert attributes of each table.
Step 5 : Insert All the data into each table.
Step 6 : Open the SQL Editor.
Step 7 : Type SQL command to find customer name from CLAIM table.

SELECT custname FROM CUSTOMER


WHERE custid IN (SELECT custid FROM CAR_CLAIM);

Step 8 : Open the SQL Editor.


Step 9 : Type SQL command to display component ID, component name and price where price
is between 200 and 400.

SELECT compID, compName, price FROM COMPONENT


WHERE price BETWEEN 200 AND 400;

Step 10 : Open the SQL Editor and type SQL command to display car number begin with D.

SELECT custid, custname, car_number FROM


CUSTOMER WHERE car_number like 'D%';

Step 11 : Open the SQL Editor and type SQL command to display claim ID and quantity where
claim number is CL001 and CL012.

SELECT claimID, quantity FROM COMPONENT_CLAIM


WHERE claimID IN ("CL001","CL012");

Page 13 of 31
DFC 20203 DATABASE DESIGN

Activity 5D

Activity Outcome: Able to understand and apply SQL Functions.

(Refer Activity 5C)

Procedures:

Step 1 : Open the SQL Editor and type SQL command to find the minimum value for price
in the COMPONENT table

SELECT MIN(price) AS MINPRICE


FROM CAR_COMPONENT;

Step 2 : Open the SQL Editor and type SQL command to find the maximum value for
price in the COMPONENT table

SELECT MAX(price) AS MAXPRICE


FROM CAR_COMPONENT;

Step 3 : Open the SQL Editor and type SQL command to find the average value for price
in the table COMPONENT.
SELECT AVG(price) AS AVGPRICE
FROM CAR_COMPONENT;

Step 4 : Type SQL command to find average value for quantity in the table
COMPONENT_CLAIM.

SELECT AVG(quantity) AS AVGQUANTITY


FROM COMPONENT_CLAIM;

Step 5 : Open the SQL Editor and type SQL command to sum the price in the table
COMPONENT
SELECT SUM(price) AS TOTALPRICE
FROM CAR_COMPONENT;

Page 14 of 31
DFC 2083 DATABASE DESIGN

Step 6 : Type SQL command to sum the components quantity in the table
COMPONENT_CLAIM.

SELECT SUM(quantity) AS TOTALQUANTITY


FROM COMPONENT_CLAIM

Step 7 : Open the SQL Editor and type SQL command to count the number of customers

SELECT COUNT(custid) AS NumberOfCustomer


FROM CUSTOMER;

Step 8 : Type SQL command to count the rows in CLAIM table.

SELECT COUNT(*)
FROM CAR_CLAIM

Step 9 : Open the SQL Editor and type SQL command to sum the quantity component
group by claim number.

SELECT claimID, SUM(quantity) AS TOTAL


FROM COMPONENT_CLAIM
GROUP BY claimID;

Step 10 : Open the SQL Editor and type SQL command to find the total quantity group by
claimID which less than 1 in COMPONENT_CLAIM table.

SELECT claimID, SUM(quantity) AS TOTAL


FROM COMPONENT_CLAIM
GROUP BY claimID
HAVING SUM(quantity) < 1

Page 15 of 31
DFC 20203 DATABASE DESIGN

SET 2
LAB ACTIVITY 5(i): Structured Query Language (SQL)
Duration : 4 Hours

Learning Outcomes
This Activity encompasses of activities from 5(i)A to 5(i)H.

By the end of this laboratory session, you should be able to:


1. Create database and table by using CREATE statement
2. Change table structure by using ALTER statement.
3. Manipulate the data by using INSERT INTO, DELETE, TRUNCATE, UPDATE statements.

Hardware/ Software : MySQL Workbench 5.2

Activity 5(i)A
Activity Outcome: Create a database named BOOK DETAILS.

A database is a shared, integrated computer structure that houses a collection of end-user data
and metadata. In BOOK DETAILS database, we will use it to store AUTHOR and BOOK data.

Procedure:

Step 1: Open MySQL Workbench 5.2. Double click on ‘Local Instance MySQL’ .

Click
here.

Page 16 of 31
DFC 2083 DATABASE DESIGN

Step 2: Type the following command inside the SQL editor:

CREATE DATABASE BOOK_DETAILS;

Step 3: Click on button to execute the SQL statement.

Step 4: Look at the ‘Object Browser’, where you will see BOOK_DETAILS database appears
along with other databases. Click refresh button if it did not appear.

Refresh

BOOK_DETAILS

Page 17 of 31
DFC 20203 DATABASE DESIGN

Activity 5(i)B
Activity Outcome: Create tables in BOOK_DETAILS database.
Table is a structure that will store data. In this activity, we will create two tables named
AUTHOR and BOOK to store author and book data.

Step 1: Type the following command and click button ::

USE BOOK_DETAILS;

Step 2: Type the following command and click button ::

CREATE TABLE AUTHOR


(
AUTHOR_ID VARCHAR(3),
AUTHOR_NAME VARCHAR (50),
EMAIL VARCHAR(30),
PRIMARY KEY (AUTHOR_ID)
);

DESC AUTHOR;

Step 3: Type the following command and click button ::

CREATE TABLE BOOK


(
BOOK_ID VARCHAR(3),
BOOK_TITLE VARCHAR(30),
ISBN INTEGER,
AUTHOR_ID VARCHAR(3),
PRIMARY KEY (BOOK_ID)
);

DESC BOOK;

Page 18 of 31
DFC 2083 DATABASE DESIGN

Step 4: Check the new tables in Object Browser.

Table AUTHOR

Table BOOK

Activity 5(i)C
Activity Outcome: Create duplicate table named AUTHOR2 in BOOK_DETAILS database.
We can create a copy of existing table by using command
‘CREATE TABLE <new_table_name>
AS SELECT <column_name> FROM <existing_table_name>.

Use * to select all columns.

Procedures:

Step 1: Type the following command and click button :

CREATE TABLE AUTHOR2


AS SELECT * FROM AUTHOR;

Page 19 of 31
DFC 20203 DATABASE DESIGN

Step 2: Check the new table in Object Browser.

Table AUTHOR2

Activity 5(i)D
Activity Outcome: Add column(s) in existing table.
We can add more columns by using command ALTER TABLE …ADD.

Procedures:

Step 1: Type the following command and click button :

ALTER TABLE BOOK


ADD (PUBLISHER VARCHAR(30), PUBLISHED_DATE DATE);

Step 2: Check the modified table in Object Browser.

New columns

Page 20 of 31
DFC 2083 DATABASE DESIGN

Activity 5(i)E
Activity Outcome: Modify column(s) in existing table.
We can modify column structure by using command ALTER TABLE ...MODIFY.

Procedures:

Step 1: Type the following command and click button :

ALTER TABLE BOOK


MODIFY PUBLISHED_DATE VARCHAR(10);

Step 2: Type DESC BOOK, to see the changes.

From date to varchar

Activity 5(i)F
Activity Outcome: Delete column(s) in existing table.
We can delete column by using command ALTER TABLE ...DROP.

Procedures:

Step 1: Type the following command and click button :

ALTER TABLE BOOK


DROP PUBLISHED_DATE;

Step 2: Type DESC BOOK, to see the changes.

Page 21 of 31
DFC 20203 DATABASE DESIGN

Activity 5(i)G

Activity Outcome: Add foreign key in existing table.


We can add foreign key by using command ALTER TABLE ...ADD FOREIGN KEY.

Procedures:

Step 1: Type the following command and click button :

ALTER TABLE BOOK


ADD FOREIGN KEY (AUTHOR_ID) REFERENCES AUTHOR(AUTHOR_ID) ;

Step 2: Check the modified table in Object Browser.

Foreign
key

Activity 5(i)H

Activity Outcome: Delete existing table.


We can delete table by using command DROP.

Procedures:

Step 1: Type the following command and click button :

DROP TABLE AUTHOR2;

Step 2: Look at Object Browser to see the changes.

Page 22 of 31
DFC 2083 DATABASE DESIGN

Activity 5(ii): Structured Query Language (SQL)


Duration : 2 Hours

Learning Outcomes
This activity encompasses of activities from 5(ii)A to 5(ii)C.

By the end of this activity session, you should be able to:

1. Manipulate the data by using INSERT INTO, DELETE, TRUNCATE, UPDATE


statements.

Hardware/ Software : MySQL Workbench 5.2

Activity 5(ii)A
Activity Outcome: Add record(s) in existing table.
We can add record(s) by using command INSERT INTO.

Procedures:

Step 1: Type the following command and click button :

INSERT INTO AUTHOR


VALUES(‘A01’, ‘BETTY NEELS’, ‘bettyneels@gmail.com’);
INSERT INTO AUTHOR
VALUES(‘A02’, ‘ANTHONY ROBBIN’, ‘anthonyrb@yahoo.com’);
INSERT INTO AUTHOR
VALUES(‘A03’, ‘JANE AUSTEN’, ‘janeausten@hotmail.com’);
Step 2: Type the following command and click button :
SELECT * FROM AUTHOR;
Step 3: Type the following command and click button :

INSERT INTO BOOK (BOOK_ID, BOOK_TITLE, ISBN,AUTHOR_ID)


VALUES(‘B01’,’CHAIN OF DESTINY’, 7230, ‘A01’);
INSERT INTO BOOK (BOOK_ID, BOOK_TITLE, ISBN,AUTHOR_ID)
VALUES(‘B02’,’GIANT WITHIN’, 2345, ‘A02’);
INSERT INTO BOOK (BOOK_ID, BOOK_TITLE, ISBN,AUTHOR_ID)
VALUES(‘B03’,’PRIDE & PREJUDICE’, 3456, ‘A03’);
Step 4: Type the following command and click button :

SELECT * FROM BOOK;

Page 23 of 31
DFC 20203 DATABASE DESIGN

Activity 5(ii)B

Activity Outcome: Modify record(s) in existing table.


We can modify record(s) by using command UPDATE…SET…WHERE.

Procedures:

Step 1: Type the following command and click button :

UPDATE AUTHOR
SET EMAIL = ‘betty_nl@yahoo.com’
WHERE AUTHOR_ID = ‘A01’;

Step 2: Type SELECT * FROM AUTHOR; and click button , to see the changes.

Activity 5(ii)C

Activity Outcome: Delete record(s) in existing table.


We can delete record(s) by using command DELETE or TRUNCATE.

Procedures:

Step 1: Type the following command and click button :

DELETE FROM BOOK


WHERE AUTHOR_ID = ‘A02’;

Step 2: Type SELECT * FROM AUTHOR; and click button , to see the changes.

Step 3: You can also use TRUNCATE to delete entire records from a table.

TRUNCATE BOOK;

Step 4: Type SELECT * FROM AUTHOR; and click button , to see the changes.

Page 24 of 31
DFC 2083 DATABASE DESIGN

Activity 5(iii): Structured Query Language (SQL)


Duration : 2 Hours

Learning Outcomes
This activity encompasses of activities from 5(iii)A to 5(iii)B.

By the end of this activity session, you should be able to:


1. Use SQL command with comparison and logical operators.
2. Use SQL commanf to sort data.

Hardware/ Software : MySQL Workbench 5.2

Activity 5(iii)A
Activity Outcome: Retrieve data from table by using comparison and logical operator.

We can use various comparison and logical operators such as =, <, >, IN, LIKE to retrieve data
from a database.

Procedures:

Step 1: Open MySQL Workbench 5.2. Double click on ‘Local Instance MySQL’ .

Step 2: Type the following command and click button :

USE SAKILA;

Step 3: Type the following command to display all records from table ACTOR.

Click button .

SELECT * FROM ACTOR;

Step 4: Type the following command to display only first name and last name columns.

Click button .

SELECT FIRST_NAME, LAST_NAME FROM ACTOR;

Step 5: Type the following command to display record for actor whose id is A01.

Click button .

SELECT * FROM ACTOR WHERE ACTOR_ID = 'A01';

Page 25 of 31
DFC 20203 DATABASE DESIGN

Step 6: Type the following command to display record from table FILM where its rating is PG
and length is more than 180.

Click button .

SELECT * FROM FILM


WHERE RATING = ‘PG’ AND LENGTH > 180;

Step 7: Type the following command to display record from table FILM where its length is
between 100 to 120.

Click button .

SELECT * FROM FILM


WHERE LENGTH BETWEEN 100 AND 120;

Step 8: Type the following command to display record from table ADDRESS where its district is
in Hiroshima, Nagano or Osaka.

Click button .

SELECT * FROM ADDRESS


WHERE DISTRICT IN ('HIROSHIMA','NAGANO','OSAKA');

Step 9: Type the following command to display record from table ACTOR where his/her first
name start with R.

Click button .

SELECT * FROM ACTOR


WHERE FIRST_NAME LIKE 'R%';

Step 10: Type the following command to display record from table ACTOR where the second
letter in his/her name is R.

Click button .

SELECT * FROM ACTOR


WHERE FIRST_NAME LIKE '_R%';

Page 26 of 31
DFC 2083 DATABASE DESIGN

Activity 5(iii)B
Activity Outcome: Sort results.

We can sort the order of data by using command ORDER BY and put it at the of SQL
statement. Default order is ascending (ASC) but it can also be sorted in descending (DESC)
order.

Procedures:

Step 1: Type the following command and click button :

SELECT TITLE, FILM_ID


FROM FILM
ORDER BY TITLE;
Step 2: Type the following command and click button :

SELECT TITLE, FILM_ID


FROM FILM
ORDER BY TITLE DESC;
Step 3: Type the following command and click button :

SELECT TITLE, FILM_ID


FROM FILM
ORDER BY 2;

Page 27 of 31
DFC 20203 DATABASE DESIGN

LAB 5(iv) : Structured Query Language (SQL)


Duration : 2 Hours

Learning Outcomes
This activity encompasses of activities from 5(iv)A to 5(iv)D.

By the end of this laboratory session, you should be able to:


1. Use aggregate functions: AVG, SUM, COUNT, MIN, MAX.
2. Use SQL function:ROUND.
3. Use SQL command: GROUP BY.
4. Use SQL command: HAVING.

Hardware/ Software : MySQL Workbench 5.2

Activity 5(iv)A
Activity Outcome: Retrieve data from table by using aggregate functions.

We can use aggregate functions such as AVG, SUM, COUNT, MIN & MAX to retrieve data from
a database.

Procedures:

Step 1: Open MySQL Workbench 5.2. Double click on ‘Local Instance MySQL’ .

Step 2: Type the following command and click button :

USE SAKILA;

Step 3: Type the following command and click button :

SELECT MIN(AMOUNT), MAX(AMOUNT)


FROM PAYMENT;
Step 4: Type the following command and click button :

SELECT AVG(AMOUNT)
FROM PAYMENT;

Step 5: Type the following command and click button :

SELECT COUNT(ACTOR_ID)
FROM ACTOR;
Page 28 of 31
DFC 2083 DATABASE DESIGN

Step 6: Type the following command and click button :

SELECT SUM(AMOUNT)
FROM PAYMENT;

Activity 5(iv)B
Activity Outcome: Round off numeric values.

We can use ROUND function to limit the decimal numbers.

Procedures:

Step 1: Type the following command and click button :

SELECT ROUND(AVG(AMOUNT), 2)
FROM PAYMENT;

Activity 5(iv)C
Activity Outcome: Use GROUP BY to group results.

We can use GROUP BY to group the results. Usually it is used in conjunction with the
aggregate functions to group the result-set by one or more columns.

Procedures:

Step 1: Type the following command and click button :

SELECT STORE_ID, COUNT(CUSTOMER_ID)


FROM CUSTOMER
GROUP BY STORE_ID;

Step 2: Type the following command and click button :

SELECT RATING, COUNT(FILM_ID)


FROM FILM
GROUP BY RATING;

Page 29 of 31
DFC 20203 DATABASE DESIGN

Activity 5(iv)D
Activity Outcome: Use HAVING to filter data.

HAVING is used to filter data based on the group functions (ex. SUM). It is similar to WHERE
condition but used with group functions. Group functions cannot be used in WHERE clause.

Procedures:

Step 1: Type the following command and click button :

SELECT CUSTOMER_ID, SUM(AMOUNT)


FROM PAYMENT
GROUP BY CUSTOMER_ID
HAVING SUM(AMOUNT) < 60;

Step 2: Type the following command and click button :

SELECT RATING, COUNT(FILM_ID)


FROM FILM
GROUP BY RATING
HAVING COUNT(FILM_ID) > 200;

Page 30 of 31
DFC 2083 DATABASE DESIGN

Page 31 of 31

You might also like