Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Arithmetic Operators in SQL

Arithmetic Operators in SQL

? Arithmetic Operators in SQL

Arithmetic operators in SQL are used to perform mathematical operations on numeric data types like INT, FLOAT, DECIMAL, etc.


? List of Arithmetic Operators

OperatorDescriptionExample
+Additiona + b
-Subtractiona - b
*Multiplicationa * b
/Divisiona / b
%Modulus (remainder)a % b

? Example Table: products

idnamepricequantity
1Laptop500002
2Keyboard15005

? Example Queries

? 1. Addition (+)

SELECT name, price + 500 AS increased_priceFROM products;

? 2. Subtraction (-)

SELECT name, price - 1000 AS discount_priceFROM products;

? 3. Multiplication (*)

SELECT name, price * quantity AS total_valueFROM products;

? 4. Division (/)

SELECT name, price / quantity AS unit_priceFROM products;

? 5. Modulus (%)

SELECT name, price % 1000 AS price_remainderFROM products;

? Can Be Used In:

  • SELECT (to create calculated columns)

  • WHERE (for filtering with expressions)

  • UPDATE (to update values using math)

? Example in UPDATE

UPDATE productsSET price = price * 1.10WHERE name = 'Laptop';

? Notes

  • Be careful of division by zero.

  • Data types affect results (e.g., integer division truncates in some databases).

  • You can use aliases (AS) to name calculated columns.


Let me know if you want examples using CASE, conditions, or with GROUP BY!

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql