Learn SQL GROUP BY: THE GRID
Surveillance teams file logs around the clock. Headquarters does not want the feed, it wants the breakdown.
Mission briefing
THE GRID is chapter 6 and the introduction to SQL GROUP BY. The SURVEILLANCE_LOGS table holds thousands of raw entries tagged by SECTOR and ACTIVITY_TYPE. Counting them one filter at a time would take all night, so you group instead: one row per sector, each with its own COUNT(*).
The follow-up mission breaks the logs down by activity type and sorts the busiest categories first, combining GROUP BY with ORDER BY on an aggregate. That per-group summary is the shape of most real reporting queries, and of a large share of interview questions.
If you want the theory first, the GROUP BY and HAVING guide linked below covers the same ground.
A query pattern from this chapter
This is the shape of query you practice here, not the answer to any mission. The real stages come with their own data, objectives, and hints.
SELECT SECTOR, COUNT(*) AS LOG_COUNT
FROM SURVEILLANCE_LOGS
WHERE ACTIVITY_TYPE = 'INTRUSION'
GROUP BY SECTOR;Related guides
Free guides that pair well with this chapter:
Play Grid now
Free in your browser, desktop only. Guest mode starts instantly with no signup; sign in with Google if you want progress saved across devices.