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.
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.
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.
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.
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.
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.