Free tutorials & notes in Hindi & English · Clean code examples · Mobile friendly learning
MySQL + SQL · Lesson 61

MySQL Numeric Functions

Numeric Functions

Numeric functions calculation या display के लिए numeric expressions transform करते हैं। ये scalar functions हैं: सामान्यतः हर input row का one result।

SELECT full_name, marks,
       ROUND(marks / 100 * 5, 2) AS score_out_of_5
FROM students
ORDER BY student_id;
Aarav | 86.50 | 4.33 Meera | 91.00 | 4.55 Kabir | 74.00 | 3.70 Sana | 88.50 | 4.43

ROUND, CEIL, FLOOR और TRUNCATE

SELECT ROUND(88.50, 0) AS rounded,
       CEIL(88.50) AS ceiling_value,
       FLOOR(88.50) AS floor_value,
       TRUNCATE(88.56, 1) AS truncated;
89 | 89 | 88 | 88.5

ROUND और TRUNCATE अलग हैं। Negative में CEIL(-2.7) = -2, FLOOR(-2.7) = -3।

ABS, MOD, POW और SQRT

SELECT ABS(-12.50) AS absolute_value,
       MOD(91, 10) AS remainder,
       POW(2, 5) AS power_value,
       SQRT(81) AS square_root;
12.50 | 1 | 32 | 9

Domains validate करें: MySQL में negative real SQRT NULL देता है; division/modulo by zero SQL mode और warnings अनुसार handle करें।

Reports में Numeric Functions

SELECT full_name,
       marks,
       CASE
         WHEN marks >= 90 THEN 'A1'
         WHEN marks >= 80 THEN 'A2'
         ELSE 'B or below'
       END AS grade,
       ROUND(marks, 0) AS display_marks
FROM students
ORDER BY marks DESC;

Calculations के लिए raw values रखें और display पर round करें, जब तक official rule stored rounding न माँगे।

Precision, NULL और Safe Calculations

  • Marks, fees, money के लिए DECIMAL।
  • FLOAT/DOUBLE approximate हैं।
  • Zero denominator में NULLIF(denominator,0) लें।
  • Most functions NULL propagate करते हैं।
  • WHERE indexed column wrap करने से पहले EXPLAIN/design check करें।
SELECT obtained_marks / NULLIF(max_marks, 0) * 100
       AS percentage
FROM results;

अभ्यास

  1. हर mark one decimal पर round करें।
  2. -2.7 के CEIL/FLOOR compare करें।
  3. 86 को 5 से divide करने का remainder निकालें।
  4. Percentage को five-point score में बदलें।
  5. NULLIF-protected division लिखें।

त्वरित सारांश

  • Rounding functions के meanings अलग हैं।
  • ABS, MOD, POW, SQRT common calculations करते हैं।
  • DECIMAL exact fixed-point values बचाता है।
  • NULL, zero denominator, domains और index use handle करें।

Official संदर्भ

References 14 August 2026 को review किए गए।

अक्सर पूछे जाने वाले प्रश्न (FAQ)

ROUND और TRUNCATE में क्या अंतर है?
ROUND requested decimal place पर numeric rules अनुसार nearest value चुनता है। TRUNCATE आगे के digits बिना rounding हटाता है।
CEIL और FLOOR में क्या अंतर है?
CEIL value से छोटा न होने वाला smallest integer और FLOOR value से बड़ा न होने वाला largest integer देता है। Negative values पर difference स्पष्ट है।
MOD क्या करता है?
MOD(a,b), a को b से divide करने का remainder देता है। MySQL में % operator भी उपलब्ध है।
Money के लिए DECIMAL क्यों लें?
DECIMAL exact fixed-point values रखता है। FLOAT/DOUBLE approximate हैं और rounding surprises दे सकते हैं।
Numeric function को NULL मिले तो क्या होता है?
Most numeric functions NULL देते हैं। Missingness preserve करनी है या valid fallback, business rule से तय करें।
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

💻 लाइव कोड एडिटर

इस पेज के प्रोग्राम यहीं तैयार हैं — चलाएँ, बदलें और सीखें। कुछ भी इंस्टॉल किए बिना।
OneCompiler द्वारा संचालित। कोड एडिटर में अपने आप आ जाता है — Run दबाकर आउटपुट देखें। अगर एडिटर न खुले तो नए टैब में खोलें.