0% found this document useful (0 votes)
569 views4 pages

Codility SQL Questions & Solutions

The document contains a series of SQL practice questions and their corresponding answers, categorized by difficulty level: easy, medium, and hard. Each question involves querying specific tables to perform operations such as summing values, counting unique entries, and identifying duplicates. The queries provided demonstrate fundamental SQL concepts and techniques for data retrieval and manipulation.

Uploaded by

ahmedmagdyedris17
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
569 views4 pages

Codility SQL Questions & Solutions

The document contains a series of SQL practice questions and their corresponding answers, categorized by difficulty level: easy, medium, and hard. Each question involves querying specific tables to perform operations such as summing values, counting unique entries, and identifying duplicates. The queries provided demonstrate fundamental SQL concepts and techniques for data retrieval and manipulation.

Uploaded by

ahmedmagdyedris17
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Codility SQL Practice Questions & Answers

Easy - Question 1:

You are given a table `elements(v integer not null)`. Write a query to return the sum of all values.

SELECT SUM(v) AS total FROM elements;

Easy - Question 2:

You are given a table `data(id integer)`. Write a query to count the number of unique values in column `id`.

SELECT COUNT(DISTINCT id) AS unique_count FROM data;

Medium - Question 3:

You are given a table `items(name text)`. Write a query to return the names of items that appear more than

once.

SELECT name FROM items GROUP BY name HAVING COUNT(*) > 1;

Medium - Question 4:

You are given a table `sales(department text, amount integer)`. Write a query to return the maximum sale

amount per department.

SELECT department, MAX(amount) AS max_sales FROM sales GROUP BY department;

Hard - Question 5:

You are given a table `scores(score integer)`. Write a query to return the second highest score.

SELECT MAX(score) AS second_highest FROM scores WHERE score < (SELECT MAX(score)

FROM scores);

Hard - Question 6:

You are given two tables:

- `customers(id, name)`

- `orders(customer_id)`
Codility SQL Practice Questions & Answers

Write a query to return the names of customers who did not make any orders.

SELECT name FROM customers WHERE id NOT IN (SELECT customer_id FROM orders);

You might also like