SQL

Categories: Code Problem / Data Structures and Algorithms / Recursion (32) Code Problem / Data Structures and Algorithms / Binary Search (30) Code Problem / Data Structures and Algorithms / Linked Lists (26) Code Problem / Data Structures and Algorithms / Backtracking (26) Code Problem / Data Structures and Algorithms / Stacks and Queues (25) Code Problem / Data Structures and Algorithms / Hashing (24) Databases / SQL / Backup and Recovery (19) Code Problem / Data Structures and Algorithms / Arrays and Strings (19) Databases / SQL / Database Normalization (18) Code Problem / Data Structures and Algorithms / Time Complexity (17) Databases / SQL / Locking (16) Databases / SQL / Replication (15) Databases / SQL / SQL Queries (13) Code Problem / Data Structures and Algorithms / Graphs (13) Databases / SQL / Database Security (13)  More...

Recent solutions:

Check these solutions from our community:
Databases / SQL SQL
Write a SQL query that returns the top 10 customers by total spent.
About this solution: This solution is correct and demonstrates a level of completeness. The approach is straightforward and easy to follow.
Jan 21
Databases / SQL SQL
This technical problem involves writing a SQL query that returns the total revenue for each customer. The table schema is provided, and an example input and output are also given.
About this solution: This solution is complete and solves the problem. The approach is straightforward and easy to follow.
Jan 21
Databases / SQL DifficultyHard SQL
This technical problem involves finding all customers who have ordered a product that is out of stock. The input is three tables: customers, orders, and products. The output is the customers table with the id and name of the customers who have ordered a product that is out of stock.
About this solution: The candidate's solution is incomplete - it does not return the expected output. The candidate has correctly identified that a join is needed to combine the data from the three tables, but has not included all the necessary conditions in the WHERE clause. A better approach would be to use a LEFT JOIN and check for NULL values in the products table, as this would return all customers who have placed an order for a product that is out of stock.
Dec 01
Databases / SQL DifficultyMedium SQL
This technical problem involves writing a SQL query to find the total number of items ordered for each order in a database. The database consists of two tables, "orders" and "order_items ". The "orders" table includes the order_id for each order, while the "order_items" table includes the order_id and the number of items ordered for that particular order. The expected output is a table that lists the order_id and the total number of items ordered for each order.
About this solution: The candidate's solution is incomplete and does not solve the problem. The general approach is not clear.
Nov 30
Databases / SQL DifficultyHard SQL
Query a database for customers who live in a given state and have made a purchase within the past 30 days.
About this solution: This is a good solution that demonstrates a level of completeness and solves the problem. The approach is efficient and uses the index on the state column to find all customers in the given state, and then filters out the ones who have not made a purchase in the past 30 days.
Nov 28
Databases / SQL DifficultyHard SQL
Design a SQL query that will return the titles of all books that are currently checked out from a library catalog.
About this solution: The candidate's solution is complete and solves the problem. The candidate's approach is straightforward and easy to understand.
Nov 28
Databases / SQL DifficultyHard SQL
Given a table of data with two columns, "id" and "value", this SQL query will find all rows where the value is greater than the average value.
About this solution: The candidate's solution is correct and demonstrates a good understanding of SQL. The solution is also efficient, as it only requires one pass through the table.
Nov 28
Databases / SQL DifficultyHard SQL
This technical problem deals with finding employees who have been with a company for more than 5 years. Given a table of data with employee start and end dates, the goal is to write a query that returns all employees who satisfy the 5-year criterion. An example input and output is provided.
About this solution: The solution above is optimal because it is the most efficient way to find the employees who have been with the company for more than 5 years.
Nov 27