{"base":{"id":"cs11-08","subject":"Databases","title":"SQL with SUM, COUNT and more","scene":"mix","steps":[{"use":"cs10t3","mode":"sql","eyebrow":"Aggregate functions","title":"COUNT and MAX","body":"Aggregate functions turn many records into one answer.","actions":[{"id":"q3","label":"COUNT and MAX"}]},{"use":"data9","mode":"funcs","eyebrow":"SUM, AVERAGE, MIN, MAX","title":"Spreadsheet comparison","body":"The same ideas appear in spreadsheets.","actions":[{"id":"f0","label":"SUM"},{"id":"f1","label":"AVERAGE"},{"id":"f2","label":"MIN"},{"id":"f3","label":"MAX"}]},{"use":"cs10t3","mode":"sql","eyebrow":"Filtering first","title":"WHERE then aggregate","body":"WHERE chooses records before COUNT or SUM works on them.","actions":[{"id":"q0","label":"Query 1"},{"id":"q1","label":"Query 2"},{"id":"q2","label":"Query 3"},{"id":"q3","label":"Query 4"}]},{"use":"data9","mode":"join","eyebrow":"Two tables","title":"JOIN, then filter","body":"Real databases join tables with keys before filtering.","controls":[{"id":"min","label":"Minimum score","min":50,"max":95,"step":5,"value":70}]},{"use":"cs10t3","mode":"quiz","look":"sql","eyebrow":"Check yourself","title":"COUNT","body":"SELECT COUNT(*) FROM Planets WHERE Rocky = FALSE;","question":"What does it return?","options":["8","4","0"],"answer":1,"right":"Correct.","wrong":"Not quite."}],"more":[{"type":"cards","id":"worked","eyebrow":"Worked examples","title":"Step by step","items":[{"tag":"SUM","title":"Total sales","body":"SELECT SUM(Amount) FROM Sales WHERE Month = 'May';","code":true},{"tag":"COUNT","title":"Members in a town","body":"SELECT COUNT(*) FROM Members WHERE Town = 'Lagos';","code":true},{"tag":"AVG","title":"Average mark","body":"SELECT AVG(Mark) FROM Results;","code":true},{"tag":"Combine","title":"Sorted output","body":"SELECT Name, Mark FROM Results\nWHERE Mark >= 70\nORDER BY Mark DESC;","code":true}]},{"type":"cards","id":"mistakes","eyebrow":"Common mistakes","title":"Watch out for these","items":[{"tag":"Mistake","title":"SUM on text fields","body":"SUM works on numbers only."},{"tag":"Mistake","title":"COUNT(field) vs COUNT(*)","body":"COUNT(field) ignores empty values; COUNT(*) counts all rows."},{"tag":"Mistake","title":"Missing quotes for text","body":"WHERE Town = 'Lagos'."}]},{"type":"cards","id":"deeper","eyebrow":"Go deeper","title":"More than the lesson","items":[{"tag":"Business","title":"Dashboards","body":"Sales dashboards run SUM and COUNT queries every few seconds to show live totals."},{"tag":"Going further","title":"GROUP BY","body":"GROUP BY gives a total per category, like total sales per month."}]},{"type":"cards","id":"challenge","eyebrow":"Challenge yourself","title":"Stretch your brain","intro":"Try each one on paper before opening the card.","items":[{"tag":"Challenge","title":"Write","body":"Find the number of films longer than 120 minutes.\n\nAnswer: SELECT COUNT(*) FROM Films WHERE RunTime > 120;","code":true},{"tag":"Challenge","title":"Predict","body":"SELECT SUM(Price) FROM Items WHERE Price < 5; prices 2, 7, 4, 9 → ?\n\nAnswer: 6."}]},{"type":"activities","id":"try","eyebrow":"Try it at home","title":"Try it yourself","items":[{"title":"SQL practice","time":"20 minutes","need":["An online SQLite sandbox"],"steps":["Create a table of 6 purchases with item and price.","Use SUM, COUNT, AVG, MAX and MIN."],"why":"You run real aggregate queries.","safety":"Use made-up data only."}]},{"type":"quiz","id":"quiz","eyebrow":"Quiz","title":"Eight more questions","questions":[{"question":"SUM(Price) gives…","options":["the number of rows","the largest price","the total of Price"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"COUNT(*) counts…","options":["rows","columns","tables"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"AVG(Mark) gives…","options":["the highest mark","the mean mark","the number of marks"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"MAX(Height) gives…","options":["the total height","the average","the largest height"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"WHERE is applied…","options":["before aggregating","after printing","never with COUNT"],"answer":0,"right":"Correct.","wrong":"Not quite."},{"question":"Text in SQL conditions needs…","options":["brackets","quotes","nothing"],"answer":1,"right":"Correct.","wrong":"Not quite."},{"question":"ORDER BY Mark DESC sorts…","options":["lowest first","alphabetically","highest first"],"answer":2,"right":"Correct.","wrong":"Not quite."},{"question":"Which works only on numbers?","options":["SUM","COUNT(*)","SELECT"],"answer":0,"right":"Correct.","wrong":"Not quite."}]},{"type":"checklist","id":"check","eyebrow":"Self-check","title":"I can…","items":["use SUM, COUNT, AVG, MIN and MAX","combine aggregates with WHERE","sort with ORDER BY","predict query results"]},{"type":"keywords","id":"words","eyebrow":"Key words","title":"Words to know","items":[{"word":"Aggregate function","meaning":"Summarises many rows into one value."},{"word":"SUM","meaning":"Adds values."},{"word":"COUNT","meaning":"Counts rows."},{"word":"AVG","meaning":"Finds the mean."},{"word":"WHERE","meaning":"Filters rows."}]},{"type":"sources","id":"sources","title":"Sources","items":["SQLite documentation: aggregate functions","Raspberry Pi Foundation, Isaac Computer Science: SQL","W3C/ISO SQL standard overview","BBC Bitesize, GCSE Computer Science: SQL"]}]},"overlay":null}