You are on page 1of 6

OCT2021-FEB2022 COLUMN FUNCTIONS AND GROUPING

FACULTY OF COMPUTER AND MATHEMATICAL SCIENCE

DIPLOMA IN COMPUTER SCIENCE

(CS110)

INTRODUCTION TO DATABASE DESIGN

(ICT200)

COLUMN FUNCTIONS AND GROUPING

GROUP: CS1103C

GROUP MEMBERS:

NAME STUDENT ID

1. HUSNA HURAIYAH BINTI DHAIFUL AMRAN 2020842114

2. NURNISRIZA BINTI DE AFENDI 2020627118

3. NURUL RASYIQAH BINTI ABDUL RAZAK 2020887252

4. SITI MAISARAH BINTI ABDUL AZIZ 2020470096


OCT2021-FEB2022 COLUMN FUNCTIONS AND GROUPING

Refer to the Entity Relationship Diagram (ERD) given and answer all questions. Your answers must
contain 1) SQL statement, and 2) screenshot of the output
OCT2021-FEB2022 COLUMN FUNCTIONS AND GROUPING

1. You need to display number of attractions for each theme park. Data need to be displayed are park
code, name and number of attractions. Sort the output according to park name using ascending
method.

Answer:

SELECT t.park_code, t.park_name, COUNT(*) AS 'Number Of Attractions'


FROM attraction a
JOIN themepark t ON t.park_code = a.park_code
GROUP BY t.park_code, t.park_name
ORDER BY t.park_name ASC

2. Display park code and name, total ticket sold and total money earned.

Answer:

select t.park_code, tp.park_name,


sum(sl.line_qty)' Total Ticket Sold ',
sum(sl.line_price) as ' Total Money Earned '
from ticket t
join themepark tp on tp.park_code = t.park_code
join sales_line sl on sl.ticket_no = t.ticket_no
GROUP BY t.park_code, tp.park_name
OCT2021-FEB2022 COLUMN FUNCTIONS AND GROUPING

3. Which theme park managed to sell Adult ticket at least 10 tickets or more? Display the park code,
name, ticket type, total ticket sold and amount of money earned after selling ticket for Adult. Filter
the records

Answer:

select tp.park_code, tp.park_name, t.ticket_type,


sum(sl.line_qty) as 'Total Ticket Sold',
format(sum(sl.line_price), 2) as 'Total sold for adult'
FROM themepark tp
JOIN ticket t on tp.park_code = t.park_code
JOIN sales_line sl on t.ticket_no = sl.ticket_no
WHERE t.ticket_type = 'Adult'
GROUP BY tp.park_code, tp.park_name, t.ticket_type
HAVING sum(sl.line_qty) >= 10

4. You are required to display profit earned for all theme parks in the year 2007. Then, sort the output
based on which theme park gets the highest profit first. Data need to be displayed are as follow:
park code and name, year and total profit.

Answer:

select t.park_code, t.park_name, year(s.sale_date) as 'year',


format(sum(sl.line_price-(m.ticket_price*sl.line_qty)),2) as 'profit'
from themepark t join sales s on t.park_code = s.park_code
join sales_line sl on s.transaction_no = sl.transaction_no
join ticket m on t.park_code = m.park_code
where year(s.sale_date) = 2007
group by t.park_code,t.park_name,s.sale_date
HAVING sum(sl.line_price-(m.ticket_price*sl.line_qty))>0.00
order by sum(sl.line_price-(m.ticket_price*sl.line_qty)) desc
OCT2021-FEB2022 COLUMN FUNCTIONS AND GROUPING
OCT2021-FEB2022 COLUMN FUNCTIONS AND GROUPING

Instructions:

1. Answer this SQL assignment according to your group project team


2. Submission must attach with a cover page which contains all group members student number and
names together with necessary information related to your ICT200 group
3. Answer must contain: 1) SQL, and 2) screenshot of the output
4. Submission platform: UFUTURE
5. Submission due date: Friday, 3 December 2021, 5:00 pm

Rubric

Grading
Criteria
Poor Mediocre Good Excellent
Report Students fulfilled report requirements of this SQL assignments
Requirements 1 2 3 4
All answers (SQLs and screenshots) of every question are available and clear to
Answer
be assessed
Requirements
1 2 3 4
Students used appropriate methods as taught by the lecturer. Other methods
SQL Methods which produced the expected output will be considered as well
1 2 3 4
Students able to answer all SQL questions correctly
SQL Answers
1 2 3 4
Students do not copy answers from the other members/groups
Plagiarism
1 2 3 4

Marks: ……………... / 20

You might also like