This homework assumes you have installed the software MySQL to your computer. If not please do that first!
- Practice the concepts
- MySQL exercises
- Code along
Let's do some interactive exercises first. In the following online course, do sections 3 (Aggregate Functions) and sections 4 (Multiple Tables).
Also make time to do lesson 6-12 from the following:
This week we'll practice some more with writing SQL queries using JavaScript. For each exercise make a separate .js
file; make sure to give it an appropriate name!
Exercise 1: Identifiers
- Create a table, called
employee
. Give it the following fields:(employee_no(Primary Key), full_name, salary, address)
- Insert 20 rows in this table, use SQL Dump and write the query too.
- Write a query that adds a
foreign key
toEmployee
table that points to itself, call it asmanager
.
Exercise 2: Relationships
- Create another table, called
department with fields:
(dept_no(Primary Key), title, description, address)` - Each department can have some employees working there. What type of relationship should we implement? Do the required changes in order to implement it.
Exercise 3: Joins
- Write a query that retrieves all
employees
and their correspondingmanager's full name
. - Write a query that retrieves all
employees
and their workingdepartment
title. If noemployee
worked in a specificdepartment
, return thedepartment
too.
Exercise 4: Aggregate Functions
Write some queries to retrieve the following rows:
- All department numbers and the number of employees working there.
- Sum of the salaries of all employees.
- Average of the salaries of all employees.
- Sum of the salaries of the employees per department.
- Minimum and maximum od the salaries per department.
- For each salary value, return the number of employees paid.
After you've finished your todo list it's time to show us what you got! The homework that needs to be submitted is the following:
- MySQL exercises
Upload both to your forked Databases repository in GitHub. Make a pull request to HackYourFuture's forked repository.
Forgotten how to upload your homework? Go through the guide to learn how to do this again.
Deadline Saturday 23.59 CET