9. Analysts साठी Date आणि Time queries
9.5 Practice: महिन्याचे totals आणि उशिरा clear झालेले cheques
का (Why). ही practice bank चे रोजचे दोन प्रश्न एकत्र करते: प्रत्येक महिन्यात किती पैसे फिरले, आणि कुठले cheques उशिरा clear झाले.
काय (What). Totals साठी तुम्ही branch आणि महिन्यानुसार group करता. मग 3 दिवसांपेक्षा जास्त वेळ लागलेले cheques शोधायला julianday() वापरता. प्रत्येक branch चा total त्याच्या स्वतःच्या currency मध्ये राहतो, म्हणून London चे pounds कधीच Mumbai च्या rupees मध्ये मिसळायचे नाहीत.
कसं (How). दोन भारतीय branches साठी एक monthly query आणि उशिरा आलेल्या cheques साठी एक query run करा.
पायऱ्या
- Branch 3 (Mumbai) आणि branch 4 (Pune), दोन्ही INR मध्ये, यांचे monthly totals मिळवायला पहिलं उदाहरण run करा.
- प्रत्येक branch च्या प्रत्येक महिन्यासाठी एक row वाचा.
- 3 दिवसांपेक्षा जास्त वेळ लागलेले cheques list करायला दुसरं उदाहरण run करा.
- प्रत्येक result साठी notes मध्ये एका ओळीचा सारांश लिहा.
उदाहरणे
उदाहरण 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 चा total August मधल्या साधारण 1.9 लाख rupees पासून October मध्ये 6.57 लाखांपर्यंत वाढतो. Pune चा सगळ्यात मोठा महिना September आहे.
उदाहरण 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. तीन cheques ना 3 दिवसांपेक्षा जास्त वेळ लागला, आणि सगळ्यात हळू cheque ला 5 दिवस लागले. Clearing date नसलेले cheques list मध्ये येत नाहीत, कारण NULL सोबतचा फरक आकडा नसून NULL असतो.
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 भी बताइए। वही सबसे ज़रूरी हो सकते हैं।