9. Date and Time Queries for Analysts
9.5 Practice: Monthly Totals and Late Cheque Clearing
Why. This practice joins two everyday bank questions: how much moved each month, and which cheques cleared late.
What. You group by branch and month for totals. Then you use julianday() to find cheques that took more than 3 days. Each branch total stays in its own currency, so you never add London pounds to Mumbai rupees.
How. Run one monthly query for the two Indian branches, and one query for late cheques.
Steps
- Run the first example to get monthly totals for branch 3 (Mumbai) and branch 4 (Pune), both in INR.
- Read one row per branch per month.
- Run the second example to list cheques that took more than 3 days.
- Write a one-line summary for each result in your notes.
Examples
Example 1 · dataset: northstar_bank
SELECT branch_id,
strftime('%Y-%m', posted_at) AS month,
SUM(amount) AS total_inr
FROM transactions
WHERE branch_id IN (3, 4)
GROUP BY branch_id, month
ORDER BY branch_id, month;Output
| branch_id | month | total_inr |
|---|---|---|
| 3 | 2026-08 | 192000.0 |
| 3 | 2026-09 | 276000.0 |
| 3 | 2026-10 | 657000.0 |
| 4 | 2026-08 | 18000.0 |
| 4 | 2026-09 | 166000.0 |
| 4 | 2026-10 | 98000.3 |
Meaning. Mumbai grows from about 1.9 lakh rupees in August to 6.57 lakh in October. Pune has its biggest month in September.
Example 2 · dataset: northstar_bank
SELECT txn_id, branch_id, date(posted_at) AS posted_date, cleared_on,
julianday(cleared_on) - julianday(date(posted_at)) AS days_to_clear
FROM transactions
WHERE txn_type = 'cheque'
AND julianday(cleared_on) - julianday(date(posted_at)) > 3
ORDER BY days_to_clear DESC;Output
| txn_id | branch_id | posted_date | cleared_on | days_to_clear |
|---|---|---|---|---|
| 4 | 2 | 2026-08-28 | 2026-09-02 | 5.0 |
| 9 | 1 | 2026-09-14 | 2026-09-18 | 4.0 |
| 13 | 3 | 2026-09-25 | 2026-09-29 | 4.0 |
Meaning. Three cheques took more than 3 days, and the slowest took 5 days. Cheques with no clearing date are not listed, because a difference with NULL is NULL, not a number.
Ravindra Bagale's Tip
When you report late cheques, also report the ones not cleared yet with cleared_on IS NULL. They may be the most urgent.
Ravindra Bagale's Tip – मराठी
उशिरा आलेले cheques report करताना cleared_on IS NULL वापरून अजून clear न झालेले cheques पण सांगा. तेच सगळ्यात तातडीचे असू शकतात.
Ravindra Bagale's Tip – हिंदी
देर से आए cheques report करते समय cleared_on IS NULL से अभी तक clear न हुए cheques भी बताइए। वही सबसे ज़रूरी हो सकते हैं।