r/learnSQL • • 1d ago

How do you practice SQL beyond basic exercises?

I'm currently learning SQL and trying to move beyond simple queries and textbook exercises.

Most exercises tell you exactly what to calculate, but real business problems seem much less structured.

Where do you find realistic SQL projects that require independent thinking?

I'm also researching what could make practical SQL learning resources more useful.

41 Upvotes

18 comments sorted by

5

u/Discordbothost 1d ago

Try answering 'are deliveries getting slower?' on a dataset with order timestamps. Decide when the clock starts and how to handle canceled or undelivered orders. Check five orders by hand before you trust the query. Working out what to count is the part textbook exercises usually skip.

1

u/Outside_Aioli_7201 1d ago

Is that something people mostly develop through professional experience? Or you know any resources that teach this kind of analytical reasoning through realistic business problems?

1

u/Mobile_Education5413 23h ago

I echo Discordbothost that this is a fantastic example to work through.

Is it learnt through professional experience? Yes, mostly, but I have also recently shared something like this on the data engineering reddit channel. It has exactly this question, amongst other things.

If you are looking for material, this may be useful

https://www.reddit.com/r/dataengineering/s/ZfHhsogdsB

10

u/shine_on 1d ago

In my experience upper management want the data broken down into simple easy-to-understand statistics. They don't want reports listing rows and rows of data, they want to know things like:

  • trend analysis (are we doing better or worse this week/month/quarter than last week/month/quarter)
  • RAG analysis (RAG stands for Red Amber Green, red = nowhere near target, amber = almost there, green = target achieved or exceeded).

There are sample databases available for most servers, I use Microsoft SQL Server so I know they have databases you can download and play around with. One is called Adventure Works, another is Wide World Importers.

It'll be a very interesting SQL exercise to create your own test data, set up some salespeople, some products, some sales on different days, and see how you can slice and dice the data in different ways.

Don't just do "who's the best salesman?", do something like "who's in the top 5 in terms of number of sales?", "who's in the top 5 in terms of value of sales?"

Learn how to group and sort data in different ways, learn about window functions (which are used to rank data in different groups), learn how to compare one table with another, learn about the effects of NULLs on your queries, learn about how to handle data that's not in the right format (a person's name that's too long, a date that's had the month and day swapped round)

Maybe get an understanding of how to import data from external sources (csv files, spreadsheets etc)

Hope this is useful!

4

u/Bhanuprakash_1947 1d ago

One thing I'd suggest is practising SQL with real-world datasets rather than just solving random queries. Try working on scenarios like finding top customers, monthly revenue, duplicate records, complex joins, and query optimization. Also, don't just focus on getting the correct output; understand why the query works and how to make it efficient. That's where real SQL skills develop!

3

u/Aggressive_Ad_5454 1d ago

SQL the query language has two classes of applications, analytic and transactional.

Transactional apps are stuff like double-entry bookkeeping. You can read about that.

The whole point of analytic apps is wringing drops of wisdom out of oceans of data. To do that you need an understanding of the ocean and an idea of the wisdom you seek. To practice that you can use open-source data. Kaggle.com has some open source datasets.

I put together a tutorial on this back in the dark days of COVID. It’s not polished or anything, but you may find it helpful. https://www.plumislandmedia.net/mysql/explore-pandemic-data-with-sql/

Happy wringing!

3

u/Haunting-Eye-4314 1d ago

the best way is to work with a real dataset, for example: take an ecommerce dataset and analyse things like customer retention, repeat purchases, monthly revenue trends, product performance, etc. initially start with simple questions and gradually make them more complex. you can find dataset on kaggle

4

u/conor-robertson 1d ago

You should check out QueryCase for some practical exercises with reasoning behind them, you solve detective cases while learning SQL from WHERE statements to windows functions. There are also some sandbox schemas where you can openly practice, all in your browser😁

7

u/i_literally_died 1d ago

Conor Robertson Founder, QueryCase

AI Site, hidden posts

What a surprise

2

u/QPGMR_de 1d ago

It's from last year - but it's still nice: https://www.dbpro.app/advent-of-sql

2

u/Most_Role_1612 1d ago

download SQLite and the sakilla database. all free and lightweight btw.

Use either or Gemini/Copilot/ChatGPT to give you challenges. They're aware of these tables and just crush a topic or topics that you want.

1

u/Ok-Sorbet8774 1d ago

Check out leetquery

1

u/BigD_Jackal 1d ago

I used chatgpt mate. Asked it to give me question for practice on different levels like lots of questions and a solution document with explanation.
On trying to solve the questions on ur own forst gives u good confidence. U can aks chapter to generate practice questions and also a sample database

1

u/___Oh_Hell_Nah___ 23h ago

I registered in Leetcode with free tier acc then solve all database problems from Easy to Hard. Im about to finished Med.

1

u/chmod764 21h ago

This YouTube playlist is great. (Database Systems Research Group at Tübingen)

I didn't find the need to make it through the whole thing, but the first 7 or 8 lessons or so were very helpful for gaining a solid understanding of SQL and relational databases.