Groot Academy
SQL

Library Reservation with SQL: A 2027 Project Guide

Practise SQL with a library reservation project. Use sample data, build steps and acceptance checks in this 2027 Groot Academy guide.

By Groot Academy November 1, 2026 6 min read

Use a familiar campus workflow to practise SQL: library reservation. The user is a librarian, and the first question is: Which approved reservations consume the most planned loan days? The deliverable is a relational query and validation lab with a visible rule and repeatable evidence behind its output.

This is a 2027 study-edition project brief. All example records and operational situations are fictional. Start with basic SQL knowledge, the ability to inspect structured data and a local practice environment. The complete first version should answer the stated question before adding accounts, real integrations or additional screens.

Define the project rule

A cancelled reservation must not contribute to approved loan days, and two reservations for the same book remain separate records. For this exercise, one row represents one reservation. The stable key is record_id; book_title is the grouping or filtering label. The numeric loan_days field uses days. Accepted states are requested, approved, cancelled.

The summary selects status approved and applies sum to the selected numeric values. Keep this definition visible in the interface, response or report so another learner can reproduce it. Use positive finite values in the starter fixture and define any future zero or missing-value policy explicitly.

Choose the SQL approach

Define the grain of a row before designing tables. Use primary keys for identity and explicit constraints for values that must always be valid. Write a plain query first, then examine filtering, grouping and joins. Keep missing values distinct from genuine zeroes. A join that duplicates a parent row can make a plausible total wrong.

The three design decisions to explain in your project notes are:

  • Row grain and keys. Apply this choice to reservation records and explain its effect on loan_days.
  • Filtering before aggregation. Apply this choice to reservation records and explain its effect on loan_days.
  • Join-cardinality checks. Apply this choice to reservation records and explain its effect on loan_days.

Work through a small sample

The three records below are deliberately small enough to inspect by hand. They are a compact specification for the data shape and expected result, and can later be expanded into a larger synthetic fixture.

[
  {
    "record_id": "library-reservations-01",
    "book_title": "Python Basics",
    "loan_days": 25,
    "status": "approved",
    "recorded_on": "2027-01-04"
  },
  {
    "record_id": "library-reservations-02",
    "book_title": "Java Workshop Notes",
    "loan_days": 40,
    "status": "requested",
    "recorded_on": "2027-01-05"
  },
  {
    "record_id": "library-reservations-03",
    "book_title": "SQL Pocket Guide",
    "loan_days": 15,
    "status": "approved",
    "recorded_on": "2027-01-06"
  }
]

Only the first and third records match approved. Their loan_days values are 25 and 15; the full-fixture result is 40 days, with 2 matching records. Selecting book_title = Python Basics leaves the first record, so the result becomes 25 days, with 1 match. This provides two independent checks for the filter and aggregation.

The full-fixture output contract is:

{
  "matching_count": 2,
  "operation": "sum",
  "value": 40,
  "unit": "days"
}

Check the result by book_title

The overall figure answers the all-records version of the question. Grouping by book_title produces the following separate expectations, using the same approved rule. The middle group has a record in the source fixture but no qualifying observation.

book_title Matching records Sum (days)
Python Basics 1 25
Java Workshop Notes 0 0
SQL Pocket Guide 1 15

Use this breakdown when answering the group-level question. Compare like-for-like units and keep the matching count visible, especially for averages. A different filter changes which records enter the calculation; it does not change the meaning of the metric.

The code blocks describe sample data and an expected result. Implement the surrounding feature using the installed version of your chosen tools, then save the actual run evidence separately from these expectations.

Build the feature in three passes

1. Define identity and row grain

One record represents one reservation, not one book_title label. Give record_id a uniqueness constraint and describe the allowed status values. Model loan_days as a numeric quantity with a documented days unit rather than an arbitrary string.

2. Write the filtered aggregation

Filter to status approved before applying the sum to loan_days. Add a book_title filter as a separate condition. Inspect the matching records before grouping; this exposes duplicate rows and incorrect joins that an attractive total can conceal.

3. Check changes and reconciliation

Try a valid update and a rejected invalid record, then rerun the summary. Compare source-row counts with the aggregate input. Explain what an absent field, an empty group and a repeated identifier mean in the chosen storage design.

Find the mistake before polishing the result

A useful defect to introduce deliberately is: A cancelled booking is still included in the total. First reproduce it against the fixture, then identify the smallest rule or state transition that explains the mismatch. Fix that boundary and rerun the full-fixture and selected-label examples. This creates a stronger explanation than changing several unrelated parts until the screen looks right.

The scenario-specific acceptance check is: Cancel one approved reservation and prove that only its loan days leave the result. Preserve before-and-after evidence. Add a missing book_title, a negative loan_days, an unrecognised status and a duplicate record_id as separate invalid cases. Define the rejection or duplicate-handling policy before testing, and verify that invalid input does not silently change valid existing records.

Check the SQL concerns as well:

  • A joined total must reconcile to source rows.
  • Missing values need an explicit policy.
  • Equal labels must not merge distinct identifiers.

For an empty filter match, the expected sum value is 0. Keep matching_count at zero. This distinction prevents an empty dataset from being interpreted as a measured observation.

Explain the finished work in a portfolio

Show the librarian question, the record definition and the expected calculation first. Then demonstrate a book_title filter and the acceptance check. Include the fixture, setup instructions, chosen tool versions, actual test output and one remaining limitation in the repository. If you show a screenshot, pair it with the input that produced it. Another learner should be able to repeat the same result from a clean checkout.

For a focused extension, add a second book_title selection and compare the two groups using the same rule. Specify how missing groups appear and keep the original fixture as a regression case. Expand scope only after the current calculation, state handling and recovery path remain understandable.

Questions learners often ask

Which reservation records belong in the result?

Select records whose status is exactly approved and that satisfy the chosen book_title filter. Other states remain in the source data and can have separate summaries. Follow the domain rule above when a record changes state.

What should happen when no records match?

Return a zero total with a matching count of zero and a clear empty-result message. Keep the applied filter visible so the user can change it. Avoid using a loading indicator for a completed request that simply has no matching data.

How can I prove the loan_days result is correct?

Reconcile the first and third sample records, then repeat the calculation for Python Basics alone. Save both expected and actual outputs, and rerun the scenario-specific acceptance check after making a change.

Continue learning with Groot Academy

Use this exercise as a concrete discussion point when choosing a learning path. Browse the current Groot Academy course directory and ask about the current syllabus, learning mode and project practice. Course availability and batch details should be confirmed directly with the academy.

For implementation details, consult the official SQL documentation matching the tools you install. This project defines an original practice brief; it does not depend on a forecast about 2027 software releases.

Continue with Workshop Seat Booking using SQL, or compare Library Reservation using MongoDB. These companion practice guides are part of the 2027 learning collection.

Practise the concepts in a structured learning path

Browse the current Groot Academy course directory and ask about the current syllabus and project practice.

Browse current courses