WeCodeAcademy

Step 7: The report, and the same questions in SQL

Package the analysis in one function that returns the headline numbers, and print them as a report. A function can be tested and run on tomorrow's log.

Examplepython
Open in editor »

For big logs the data would live in a database. Every question above is also a short SQL query. Compare them with the Python versions:

Examplesql
Open in editor »

GROUP BY replaces the Counter, AVG replaces the manual sum and divide, and HAVING COUNT(*) >= 3 is the suspicious-IP threshold. You have built a log analyser: parsing, counting, percentiles, time buckets, simple security detection and a report. Where next: stream the file line by line instead of loading it whole, chart the numbers, and alert by email when the error rate passes a limit.

Quick check

Which SQL clause is the equivalent of the threshold check for failed logins?

Finish the quick check (and any code exercise) to complete this lesson, or mark it done yourself.

Tip: use the left and right arrow keys to move between lessons.