← Back to MySQL Course | Chapter 8: Operators & Conditional Logic | Lesson 1 of 5

Arithmetic Operators

Arithmetic operators आपके calculator buttons हैं, MySQL को एक query में numbers add, subtract, multiply और divide करने देते हुए।
Syntax
sql
SELECT column1 + column2, column1 - column2,
       column1 * column2, column1 / column2, column1 % column2
FROM table_name;

Addition Operator (+)

Addition operator दो numbers को जोड़कर उनका total sum ढूँढता है, जैसे एक base price और shipping fee को combine करना। यह SQL math में एक fundamental operator है और SELECT, WHERE, या UPDATE expressions के अंदर same तरह काम करता है।

उदाहरण: Addition Operator (+)

sql
SELECT base_price + shipping_fee AS total FROM orders;

Subtraction Operator (-)

Subtraction operator एक number को दूसरे से deduct करता है। आप इसे दो values के बीच difference ढूँढने के लिए इस्तेमाल कर सकते हैं, जैसे date functions के साथ combine होने पर एक due date और आज की date के बीच days calculate करना।

उदाहरण: Subtraction Operator (-)

sql
SELECT price - discount AS final_price FROM orders;

Multiplication Operator (*)

Multiplication operator दो numbers को साथ multiply करता है। यह values scale करने या totals calculate करने के लिए उपयोगी है, जैसे एक line-item subtotal पाने के लिए unit price को quantity से multiply करना।

उदाहरण: Multiplication Operator (*)

sql
SELECT unit_price * quantity AS total FROM order_items;

Division Operator (/)

Division operator पहले number को दूसरे से divide करता है। यह MySQL में हमेशा एक float result return करता है, यहाँ तक कि दो integers को evenly divide करते समय भी, इसलिए अगर आपको एक whole number चाहिए तो round या cast करना याद रखें।

उदाहरण: Division Operator (/)

sql
SELECT 10 / 4 AS result; -- always returns a float, even for exact division

Modulo Operator (%)

Modulo operator एक division का remainder return करता है। यह odd या even numbers ढूँढने के लिए, या rows को एक fixed संख्या के buckets में evenly distribute करने जैसे tasks के लिए helpful है।

उदाहरण: Modulo Operator (%)

sql
SELECT id, id % 2 AS remainder FROM users; -- 0 = even, 1 = odd
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. यह उम्मीद करना कि / एक integer return करेगा, जबकि 5 / 2 2.5000 देता है (integer division के लिए DIV इस्तेमाल करें)।
  2. एक NULL column के साथ arithmetic करना, ताकि पूरा result NULL बन जाए।
  3. zero से divide करना, जो NULL return करता है (और strict mode में एक warning या error देता है)।
🔒

Chapter Quiz — Complete all 5 topics to unlock

0/5 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.