Ravindra BagaleCourses & study guides Track your progress

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 करा.

पायऱ्या

  1. Branch 3 (Mumbai) आणि branch 4 (Pune), दोन्ही INR मध्ये, यांचे monthly totals मिळवायला पहिलं उदाहरण run करा.
  2. प्रत्येक branch च्या प्रत्येक महिन्यासाठी एक row वाचा.
  3. 3 दिवसांपेक्षा जास्त वेळ लागलेले cheques list करायला दुसरं उदाहरण run करा.
  4. प्रत्येक 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_idmonthtotal_inr
32026-08192000.0
32026-09276000.0
32026-10657000.0
42026-0818000.0
42026-09166000.0
42026-1098000.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_idbranch_idposted_datecleared_ondays_to_clear
422026-08-282026-09-025.0
912026-09-142026-09-184.0
1332026-09-252026-09-294.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.