SQL Problems

Looking to level up your SQL skills?

Whether you’re preparing for interviews, practicing for certifications, or building real-world data pipelines — solving practical SQL problems is the best way to learn.

At DataForGeeks, we’ve curated a growing collection of SQL problems, ranging from beginner to advanced, with clear solutions and explanations.

What You’ll Find Here:

  1. Real-world inspired SQL problems
  2. Interview-style SQL questions
  3. Solutions using modern SQL (Window functions, CTEs, Analytics)
  4. Tips for optimizing queries
  5. Practice datasets

Why Practice with These Problems?

  • Understand how SQL is used in production systems
  • Learn patterns for data aggregation, joins, windowing, subqueries
  • Prepare for Data Engineer, Analyst, and Data Scientist roles
TitleContentDateTags
Columns with Sum of positive and negative values.A table with single column is provided with integer values. Task is to create two …2019/07/152019-07-15 18:18:48
Sales Analysis – 3Tables – product and sales are provided. Write SQL query to identify products which were …2019/05/282019-05-28 19:10:50
SQL Contest – 14 days hackathonStarted on 1st July, 2019 – 2 weeks long hackathon was conducted, which concluded on …2019/03/172019-03-17 20:12:59
Post Views – 2Post views are being analysed using post_views table. This table contains information of all views …2018/12/142018-12-14 08:33:44
Post Views – 1Post views are being analysed using post_views table. This table contains information of all views …2018/12/142018-12-14 08:27:25
Product Sales Analysis – 3Write a SQL query that selects the product id, sale year, quantity, and price for the first year of …2018/08/272018-08-27 17:22:00
Product with sales increasing every yearA multinational Company is going through very bad timings and now want to focus on …2018/08/152018-08-15 11:50:35
Product Sales Analysis – 2Write an SQL query that reports the total quantity sold for every product id.   …2018/07/122018-07-12 14:26:29
Product Sales Analysis – 1Write an SQL query that reports all product names of products in the “sales” table …2018/07/122018-07-12 14:07:43
Shortest distance in line on x-axisPoints of x coordinates are stored in table “points“. All entries of these points in …2018/06/092018-06-09 16:55:54
Sales Analysis – 1Tables – product and sales are provided. Being area manager, you are looking for best …2018/05/282018-05-28 18:35:29
Sales Analysis – 2Tables – product and sales are provided. product table holds data of all products and …2018/05/282018-05-28 05:20:03
Tutor taking atleast 3 classes for a studentTutor data is provided tutor_students table below. Table contains data of a month with tutor_id …2018/04/082018-04-08 18:05:57
Gamers Analysis – 1Write an SQL query and identify first login date for each gamer.   Input Table: gamers_activity player_id …2018/03/122018-03-12 15:19:25
Gamers Analysis – 2Write a SQL query that identify the device that was first used to log in …2018/03/012018-03-01 17:23:37