Summarize Many Rows · practice
Add Up the Loan Days
The count says that six items contributed, but it does not say how much lending time those rows represent together. Add the loan_days values from the visible catalog and the total is 54.0, including the half days stored for two electronics items.
Open summary.sql. Add a comma after the existing count and place this second result FROM items:
SUM(loan_days) AS total_loan_days
The complete query should be:
SELECT
COUNT(*) AS item_count,
SUM(loan_days) AS total_loan_days
FROM items;
Press Run and look for one row with two values:
Columns: item_count | total_loan_days
6 | 54.0
SUM(loan_days) asks SQLite to add that column’s values across the same six source rows. The count answers “how many?” while the sum answers “how much in total?” They sit in one result row because both summarize the complete set.
You can verify the visible total without memorizing a formula: 7 + 3 + 7 + 14 + 2.5 + 20.5 is 54.0. SQLite performs that addition for whatever rows are actually present, so the query keeps working when the catalog grows or the periods change.
The catalog contains 2.5 and 20.5, even though loan_days was declared with INTEGER affinity. When you created that column, you saw that SQLite stores an actual numeric
Keep COUNT(*) AS item_count as the first result column. You are growing one useful summary, not replacing the earlier question each time. The comma tells SQLite that the SELECT
Submit uses other positive whole and fractional periods. It compares the numeric total, not a formatted phrase such as 54 days. Let SQLite return the number directly under the total_loan_days heading.
If Run reports a SUM, check for the comma between the two expressions. If the total matches the item count, make sure SUM receives loan_days rather than 1 or an ID.
Your single summary row now carries two different facts about the same catalog: the number of contributing items and the total of their lending periods.
Task
Add SUM(loan_days) AS total_loan_days as the second result column in summary.sql. Keep COUNT(*) AS item_count first.
Run the query, check that fractional days contribute to the total, and submit it.