tricky sql query
5 Tricky SQL Queries Solved - KDnuggets
SQL(Structured Query Language) is a very important tool in a data scientist's toolbox. Mastering SQL is not only essential in an interview point of view, but a good understanding of SQL by being able to solve complex queries will keep us above everyone in the race. In this article, I will talk about 5 tricky questions I found and my approaches to solve them. Note -- Each query can be written in different ways. Try to think about the approach before moving on to my solutions.
5 Tricky SQL Queries Solved -- Part II
Given a table of students and their GRE test scores, write a query to return the two students with the closest test scores and their score difference. If there exists more than one pair, sort their names in ascending order and then return the first resulting pair. This requires some creative thinking in SQL. Since there is only one table with two columns we need to self-reference different creations of the same table. We can solve these kinds of problems by visualizing two tables having the same values.