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 DifficultyHard SQL
Given an XML document, write a SQL query to find all the nodes with a given attribute value.
About this solution: The candidate's solution is complete and solves the problem. The candidate's approach is to use the XMLTABLE function to parse the XML document and return a table of values. The XMLTABLE function takes an XML document and a path expression as arguments. The path expression is used to extract the desired nodes from the XML document. The XMLTABLE function returns a table with a column for each node in the path expression. The XMLTABLE function is used in the FROM clause of the SQL query. The WHERE clause is used to filter the results to only include rows where the value of the attribute is equal to the desired value.
Nov 27
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
Given a table of data representing customer orders, this SQL query finds the order with the highest total value.
About this solution: The solution above is optimal because it uses the GROUP BY clause to group the data by customer_id and order_id, and then uses the SUM function to calculate the total value of each order. The solution then uses the ORDER BY clause to sort the data by total_value in descending order, and then uses the LIMIT clause to return only the first row.
Nov 27
Databases / SQL DifficultyHard SQL
Given a table of data, write a SQL query to partition the data by year. The table should have three columns: id, value, and year. The query should return the id, value, and year for each row in the table.
About this solution: The solution above is correct and demonstrates a level of completeness. It solves the problem by partitioning the data by year. The approach is efficient and straightforward.
Nov 27
Databases / SQL DifficultyHard SQL
This problem asks the reader to write a cursor to update the prices of all products in a table by 10%. The table is provided as input, and the expected output is also shown.
About this solution: The candidate's solution is correct and demonstrates a level of completeness. The candidate has correctly used a cursor to iterate over the table and update the prices of all products by 10%. The candidate's approach is sound and the solution is efficient.
Nov 27
Databases / SQL DifficultyHard SQL
This technical problem involves writing a SQL query to return all customers who have made a purchase in the last 30 days, as well as the total amount they have spent.
About this solution: This solution is complete and solves the problem. It uses a JOIN to combine information from the customers and purchases table and then uses the GROUP BY clause to sum the total amount spent for each customer. The solution also uses the DATE_SUB function to only consider purchases made in the last 30 days.
Nov 27
Databases / SQL DifficultyHard SQL
To find the sum of all values in a table with two columns, "id" and "value", use the following query: SELECT SUM(value) FROM table
About this solution: The candidate's solution is correct and demonstrates a complete understanding of how to find the sum of all values in a table. The candidate's approach is also optimal, as they have used the SUM function which is specifically designed to sum all values in a column.
Nov 27
Databases / SQL DifficultyHard SQL
Given a table of products and their prices, write a SQL query to find the products with the highest price per unit.
About this solution: The candidate's solution is correct and demonstrates a good understanding of SQL.
Nov 26