Ravindra BagaleCourses & study guides Track your progress

6. Analysts ना रोज भेटणारे SQL Data Types

6.5 Practice: गोंधळलेल्या bank data मधले चुकीचे types शोधा (फक्त वाचून)

का (Why). Manager ने total बघण्याआधी, तो total चुकवणारे rows तुम्ही शोधले पाहिजेत.

काय (What). ही practice फक्त SELECT वापरते, म्हणून database मध्ये काहीही बदलत नाही. तुम्ही गोंधळलेला raw_amount text आणि स्वच्छ amount column यांची तुलना करता आणि न जुळणारा प्रत्येक row list करता.

कसं (How). raw_amount NULL असेल, किंवा त्याची CAST value amount पेक्षा वेगळी असेल, तर तो row flag करा.

पायऱ्या

  1. प्रत्येक problem row कारणासह list करायला पहिलं उदाहरण run करा.
  2. दुसऱ्या उदाहरणाने problem rows मोजा.
  3. Row ids notes मध्ये लिहा आणि data owner ने प्रत्येक row कसा दुरुस्त करावा ते ठरवा.
  4. या practice मध्ये UPDATE किंवा DELETE चालवू नका.

उदाहरणे

उदाहरण 1 · dataset: northstar_bank

SELECT txn_id, raw_amount, amount,
       CASE
         WHEN raw_amount IS NULL THEN 'missing text'
         ELSE 'text does not match amount'
       END AS problem
FROM transactions
WHERE raw_amount IS NULL
   OR CAST(raw_amount AS REAL) <> amount
ORDER BY txn_id;

Output

txn_idraw_amountamountproblem
21,200.501200.5text does not match amount
1356,00056000.0text does not match amount
15N/A91000.0text does not match amount
2047000.0missing text

Meaning. चार rows कडे लक्ष द्यायला हवं. दोघांच्या text मध्ये commas आहेत, एकामध्ये N/A text आहे, आणि एकाचा text नाहीच. यापैकी कुठलाही row total साठी विश्वासाचा नाही.

उदाहरण 2 · dataset: northstar_bank

SELECT COUNT(*) AS problem_rows
FROM transactions
WHERE raw_amount IS NULL
   OR CAST(raw_amount AS REAL) <> amount;

Output

problem_rows
4

Meaning. हा count report करता येईल असा एक आकडा देतो, उदाहरणार्थ: import केलेल्या 25 पैकी 4 rows स्वच्छ करायला हव्यात.

Ravindra Bagale's Tip

Keep the raw imported column and add a clean column next to it. Then you can always explain where a number came from.