You are on page 1of 4

IM 101 – Fundamentals of Database System

Final Project

CYRUS NOVO S SERVAS


BSIT 2A
Activity: Self-Check
Instruction: Write the SQL statements of the following result sets.
Employee
id employee_name department_id
1 Homer Simpson 4
2 Ned Flanders 1
3 Barney Gumble 5
4 Clancy Wiggum 3
5 Moe Syzslak NULL

Department
id department_name
1 Sales
2 Engineering
3 Human Resources
4 Customer Service
5 Research And Development

1.
id employee_name department_id department_id department_name
1 Homer Simpson 4 4 Customer Service
2 Ned Flanders 1 1 Sales
3 Barney Gumble 5 5 Research And Development
4 Clancy Wiggum 3 3 Human Reso


SELECT employee.*, department_id, department_name
From department
INNER JOIN employee
ON department.id = employee.id
LIMIT 0, 4;
2.
id employee_name department_id department_id department_name
1 Homer Simpson 4 4 Customer Service
2 Ned Flanders 1 1 Sales
3 Barney Gumble 5 5 Research And Development
4 Clancy Wiggum 3 3 Human Resources
5 Moe Szyslak NULL NULL NULL
IM 101 – Fundamentals of Database System
Final Project


SELECT employee.*, department_id, department_name
From employee
LEFT JOIN department
ON department.id = employee.department_id
ORDER BY employee.id
LIMIT 0, 5;
3.
id employee_name department_id department_id department_name
2 Ned Flanders 1 1 Sales
NULL NULL NULL 2 Engineering
4 Clancy Wiggum 3 3 Human Resources
1 Homer Simpson 4 4 Customer Service
3 Barney Gumble 5 5 Research And Development


SELECT employee.*, employee.department_id, department_name
From employee
RIGHT JOIN department
ON department.id = employee.department_id
ORDER by employee.department_id;

Activity: Self-Check
Write the SQL statements of the following result sets.
IM 101 – Fundamentals of Database System
Final Project

Table Name: Shows


Show_ID Title Ticket_Price
1 El Filibusterismo 500.00
2 Noli Me Tangere 450.00
3 Avatar 500.00
4 Harry Potter 800.00

Table Name: Show_Date

SHOW_DATE_ID SHOW_ID SHOW_DATE START_TIME Sales


1 1 01/15/11 9:00 150000.00
2 1 01/18/11 7:00 87001.00
3 1 01/25/11 8:00 230007.00
4 2 02/05/11 7:00 87000.00
5 2 02/05/11 7:00 123760.00
6 2 02/10/11 8:00 4000890.00
7 4 02/11/11 6:00 560040.00

1. Show the Title, and number of Show Date for Show_ID ‘1’ (use ‘No of Show’ as alias
for Show_Date)


SELECT Title, show_date as 'No of Show', shows.Show_ID
From shows
LEFT JOIN show_date
ON shows.Show_ID = show_date.Show_ID
LIMIT 0, 3;

2. Show the Title, Ticket_Price, and highest sales for each Title showing from January 1 –
February 10 in ascending order.


SELECT Title, Ticket_Price, show_date, Sales
From shows
LEFT JOIN show_date
ON shows.Show_ID = show_date.Show_ID
ORDER BY show_date.Sales ASC
LIMIT 0,7;
IM 101 – Fundamentals of Database System
Final Project

3. Show the Title, and total sales of each Show order by Title in descending order. (Use
‘Total Gross’ as alias for total sales of each movie.)


SELECT Title, SUM(Sales) as 'Total Gross'
From shows
LEFT JOIN show_date
ON shows.Show_ID = show_date.Show_ID
GROUP BY Title
ORDER BY shows.Title DESC

4. Display the title, show date, ticket price which show date between 01/15/11 and
01/25/11 in descending order.


SELECT Title, show_date.SHOW_DATE, Ticket_Price
From shows
LEFT JOIN show_date
ON shows.Show_ID = show_date.Show_ID
GROUP BY shows.Title, show_date.SHOW_DATE >= 2011/01/15,
show_date.SHOW_DATE <= 2011/01/25
LIMIT 1, 4;

5. Display the Show_ID, Title, Ticket_Price, Show_Date, and Start_Time for shows that
starts at 7:00 (use INNER JOIN and use ‘Starts at 19:00’ as alias).


SELECT shows.Show_ID, Title, Ticket_Price, show_date.SHOW_DATE,
show_date.START_TIME as 'Start at 19:00'
From shows
INNER JOIN show_date
ON shows.Show_ID = show_date.Show_ID
WHERE show_date.START_TIME = '07:00:00';

6. Show the Title, Ticket_Price, and Start_Time of all the shows showing from January 1 –
February 10 in ascending order. (use RIGHT JOIN)


SELECT Title, Ticket_Price, show_date.START_TIME
From shows
RIGHT JOIN show_date
ON shows.Show_ID = show_date.Show_ID
ORDER BY show_date.SHOW_DATE ASC;

You might also like