## Database Optimization

#### Recent solutions:

Check these solutions from our community:
Databases / SQL DifficultyHard SQL
This technical problem deals with writing a SQL query to find the number of distinct values in each column of a table. The input is a table with two columns, and the output is the number of distinct values in each column.
About this solution: The solution above is optimal because it uses the COUNT function with the DISTINCT keyword. This will count the number of unique values in each column.
Jan 29
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
This technical problem deals with finding the second highest salary from a table of employees. An example table is given, along with the expected output.
About this solution: The candidate's solution is correct and demonstrates a good understanding of SQL. The solution is also efficient, as it uses the ORDER BY and LIMIT clauses to sort the table by salary in descending order and then return the second highest salary.
Nov 27
Databases / SQL DifficultyHard SQL
Write a SQL query to find all pairs of rows in a table where the values in the two columns are within 10% of each other.
About this solution: This solution is correct and demonstrates a level of completeness. It solves the problem and uses the correct SQL syntax. The approach is straightforward and easy to understand.
Nov 22
Databases / SQL DifficultyHard SQL
To find the top 10 most common values in a given column with millions of rows, you can use a SQL query.
About this solution: The candidate's solution is optimal and demonstrates a complete understanding of the problem. The candidate has used the GROUP BY and ORDER BY clauses to group the values and order them by count, and the LIMIT clause to limit the number of rows returned.
Nov 20
Databases / SQL DifficultyMedium SQL
This technical problem involves writing a SQL query that returns the id, name, and salary of all employees with a salary greater than \$50,000.
About this solution: The solution above is optimal because it uses the WHERE clause to filter the results.
Nov 07
Databases / SQL DifficultyMedium SQL
Write a SQL query to find the second highest salary from the employees table. The table has columns for id and salary. The query should return the salary column.
About this solution: The solution above is optimal because it uses a subquery to find the maximum salary and then uses that value to find the second highest salary.
Nov 06