SQL Online Test

Practice your skills and earn a certificate of achievement when you score in the top 25%.

For Companies

Test candidates with real-world problems and interview the best ones.

About the test

The SQL online test assesses SQL skills using live coding tasks that require writing CRUD operations in order to extract, combine, and manipulate data. SQL queries on this test can be executed in MySQL, MS SQL, or SQLite databases.

The assessment includes work-sample tasks such as:

A good database admin, back-end developer, or data analyst all need a solid understanding of SQL to interface and access an SQL database efficiently.

Sample public questions

Aggregation

App usage data are kept in the following table:

TABLE sessions id INTEGER PRIMARY KEY, userId INTEGER NOT NULL, duration DECIMAL NOT NULL

Write a query that selects userId and average session duration for each user who has more than one session.

See the example case for more details.

Conditions Subqueries

The following data definition defines an organization's employee hierarchy.

An employee is a manager if any other employee has their managerId set to this employee's id. That means John is a manager if at least one other employee has their managerId set to John's id.

TABLE employees id INTEGER NOT NULL PRIMARY KEY managerId INTEGER name VARCHAR(30) NOT NULL FOREIGN KEY (managerId) REFERENCES employees(id)

Write a query that selects only the names of employees who are not managers.

See the example case for more details.

Constraints Create Table Database Schema

The following two tables are used to define users and their respective roles:

TABLE users id INTEGER NOT NULL PRIMARY KEY, userName VARCHAR(50) NOT NULL TABLE roles id INTEGER NOT NULL PRIMARY KEY, role VARCHAR(20) NOT NULL

The usersRoles table should contain the mapping between each user and their roles. Each user can have many roles, and each role can have many users.

Modify the provided SQL create table statement so that:

See the example case for more details.

Aggregation

An insurance company maintains records of sales made by its employees. Each employee is assigned to a state. States are grouped under regions. The following tables contain the data:

TABLE regions id INTEGER PRIMARY KEY name VARCHAR(50) NOT NULL TABLE states id INTEGER PRIMARY KEY name VARCHAR(50) NOT NULL regionId INTEGER NOT NULL FOREIGN KEY (regionId) REFERENCES regions(id) TABLE employees id INTEGER PRIMARY KEY name VARCHAR(50) NOT NULL stateId INTEGER NOT NULL FOREIGN KEY (stateId) REFERENCES states(id) TABLE sales id INTEGER PRIMARY KEY amount INTEGER NOT NULL employeeId INTEGER NOT NULL FOREIGN KEY (employeeId) REFERENCES employees(id)

Management requires a comparative region sales analysis report.

Write a query that returns:

Employees can have multiple sales. A region with no sales should be also returned. Use 0 for average sales per employee for such a region when calculating the 2nd and the 3rd column.

See the example case for more details.