<<Back>>

Coding tasks for IT interview

Problem: SQL query with grouping.

Given the following tables:

SELECT * FROM users;
user_id  username
1        John Doe                                                                                            
2        Jane Don                                                                                            
3        Alice Jones                                                                                         
4        Lisa Romero
SELECT * FROM training_details;
user_training_id  user_id  training_id  training_date
1                 1        1            "2015-08-02"
2                 2        1            "2015-08-03"
3                 3        2            "2015-08-02"
4                 4        2            "2015-08-04"
5                 2        2            "2015-08-03"
6                 1        1            "2015-08-02"
7                 3        2            "2015-08-04"
8                 4        3            "2015-08-03"
9                 1        4            "2015-08-03"
10                3        1            "2015-08-02"
11                4        2            "2015-08-04"
12                3        2            "2015-08-02"
13                1        1            "2015-08-02"
14                4        3            "2015-08-03"

Write a query to to get the list of users who took the a training lesson more than once in the same day, grouped by user and training lesson, each ordered from the most recent lesson date to oldest date.

Problem: SQL query from several tables to link data #1

There is the following database schema:
employee(employee-name, street, city)
works(employee-name, company-name, salary)
company(company-name, city)
manages(employee-name, manager-name)

Task: Build a SQL query to find:
the names, street address, and cities of residence for all employees
who work for 'First Bank Corporation' and earn more than $10,000.

Problem: SQL query from several tables to link data #2

There is the following database schema:
employee(employee-name, street, city)
works(employee-name, company-name, salary)
company(company-name, city)
manages(employee-name, manager-name)

Task: Build a SQL query to find:
the names of all employees in the database who live in the same cities as the companies for which they work.

Problem: SQL query from several tables to link data #3

There is the following database schema:
employee(employee-name, street, city)
works(employee-name, company-name, salary)
company(company-name, city)
manages(employee-name, manager-name)

Task: Build a SQL query to find:
the names of all employees in the database who live in the same cities and on the same streets as do their managers.

Problem: SQL query from several tables to link data #4

There is the following database schema:
employee(employee-name, street, city)
works(employee-name, company-name, salary)
company(company-name, city)
manages(employee-name, manager-name)

Task: Build a SQL query to find:
the names of all employees in the database who earn more than every employee
of 'Small Bank Corporation'. Assume that all people work for at most one company.

Problem: SQL query from several tables to link data #5

There is the following database schema:
employee(employee-name, street, city)
works(employee-name, company-name, salary)
company(company-name, city)
manages(employee-name, manager-name)

Task: Build a SQL query to find:
the names of all employees who earn more than the average salary of all
employees of their company. Assume that all people work for at most one company.

Problem: SQL query from several tables to link data #6

There is the following database schema:
employee(employee-name, street, city)
works(employee-name, company-name, salary)
company(company-name, city)
manages(employee-name, manager-name)

Task: Build a SQL query to find:
the name of the company that has the smallest payroll.