GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — GitHub - williamchenjun/DB-Revision: Revision for KCL Database winter exams. Includes SQL queries, database normalisation and data warehouse design.

BranchesTags
Open more actions menu

Latest commit

 

History

7 Commits
7 Commits

Folders and files

NameName
Last commit message
Last commit date
DataWarehouseDesign
DataWarehouseDesign
 
 
DatabaseNormalisation
DatabaseNormalisation
 
 
LICENSE
LICENSE
 
 
README.md
README.md
 
 

Repository files navigation

Database Sample Questions

Disclaimer: The problems are taken from a mock exam provided by the course. I do not take credit for them.
KCL Module Ref.: 7CCSMDDW.

Q1. Given the relation $R(A,B,C,D,E,F,G,H)$ and the set of functional dependencies

$$\{ A \rightarrow BD,\; DH \rightarrow CF,\; C \rightarrow B,\; BF \rightarrow H,\; H \rightarrow G \}$$

is the functional dependency $AF \rightarrow G$ implied?

Solution: The answer is YES. We can see that

$$\begin{align*} \because A &\rightarrow BD \implies \begin{cases}A \rightarrow B\\A \rightarrow D\end{cases}\\[1em] AF &\rightarrow BF \implies AF \rightarrow H \implies AF \rightarrow G. \end{align*}$$

(The first step is given by the splitting rule. The second step is respectively given by the axiom of augmentation and transitivity).

We are given the following database schema:

  • employee(empid, lname, location, salary, manager)
  • project(projectID, projectName, projectLeader, budget)
  • projectemployees(contractID, empID(FK), projectID(FK), contract_length)

Q2. List the last name of the employees based in London who have the lowest salary. Note that more than one employee might have the lowest salary if they have the same salary.

Solution:

SELECT lname
FROM employee
WHERE salary = (
  SELECT MIN(salary)
  FROM employee
  WHERE location = "London"
);

Q3. Which employees are working on the most projects?

Solution:

SELECT empID, COUNT(projectID) AS NumberOfProjects
FROM projectemployees
GROUP BY empID
HAVING COUNT(projectID) = (
  SELECT MAX(P) 
  FROM (
    SELECT empID, COUNT(projectID) AS P
    FROM projectemployees 
    GROUP BY empID
  )
);

We could also make it better by performing an inner join with the employee table to access more information about the employee:

SELECT employees.empID, employees.lname, employees.fname, COUNT(projectemployees.projectID) AS NumberOfProjects
FROM projectemployees INNER JOIN employees ON projectemployees.empID = employees.empID
GROUP BY projectemployees.empID
HAVING COUNT(projectemployees.projectID) = (
  SELECT MAX(P) 
  FROM (
    SELECT empID, COUNT(projectID) AS P
    FROM projectemployees 
    GROUP BY empID
  )
);

About

Revision for KCL Database winter exams. Includes SQL queries, database normalisation and data warehouse design.

Topics

data-sciencedata-warehousedatabasedatabase-designdatabase-normalizationdatawarehousedbdbmsmariadbmysqlsqlsql-practicesql-practice-problemssql-query

Resources

Readme
GPL-3.0 license
Activity

Stars

1 star

Watchers

1 watching

Forks

0 forks
Report repository

Contributors

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.