1. Calculations Across Tools

Data analysts perform calculations in:

  • Spreadsheets (Excel, Google Sheets)
  • SQL databases

Although syntax differs, the underlying mathematical logic remains the same.

Understanding the similarities helps analysts transition between tools efficiently.


2. Arithmetic Operators

An operator is a symbol that specifies a mathematical operation.

2.1 Common Arithmetic Operators (Spreadsheets & SQL)

OperationSymbolMeaning
Addition+Add values
Subtraction-Subtract values
Multiplication*Multiply values
Division/Divide values

These operators behave identically in both spreadsheets and SQL.


3. Basic Calculations in SQL

Example: Adding Two Columns

Suppose we have columns:

  • columnA
  • columnB

SQL query:

SELECT 
  columnA,
  columnB,
  columnA + columnB AS total_sum
FROM table_name;

Explanation:

  • columnA + columnB performs addition.
  • AS total_sum names the new calculated column.

4. Using Multiple Operators

If multiple operations are involved, use parentheses to control order of operations.

Example:

SELECT 
  (columnA + columnB) * columnC AS computed_value
FROM table_name;

Order of execution:

  1. Add columnA and columnB.
  2. Multiply result by columnC.

Parentheses ensure correct precedence.


5. Modulo Operator

Purpose

Returns the remainder after division.

SQL Syntax

SELECT columnA % columnB AS remainder
FROM table_name;

Spreadsheet Equivalent

In spreadsheets:

=MOD(A1, B1)

Modulo is useful for:

  • Determining even vs odd numbers
  • Cycle-based calculations
  • Partitioning data

6. Functions vs Operators

Both spreadsheets and SQL support:

  • Direct operators (+, -, *, /)
  • Functions (SUM, AVG, etc.)

7. SUM in SQL and Spreadsheets

Spreadsheet

=SUM(A1:A10)

SQL

SELECT columnA % columnB AS remainder
FROM table_name;

Both return the total of selected values.


8. Average Function

Spreadsheet

=AVERAGE(A1:A10)

SQL

SELECT AVG(columnA) AS average_value
FROM table_name;

Both calculate the mean.


9. Aggregate Functions in SQL

In SQL, functions like:

  • SUM()
  • AVG()
  • COUNT()
  • MIN()
  • MAX()

Are called aggregate functions.

Definition:
Aggregate functions operate on multiple rows and return a single value.

These are commonly used with:

GROUP BY

To compute grouped summaries.


10. Key Differences Between Spreadsheet and SQL Calculations

FeatureSpreadsheetSQL
Row-level calculationDefaultExplicit in SELECT
Column referenceCell referencesColumn names
Aggregate behaviorRange-basedTable-based
GroupingManual or PivotGROUP BY
Dataset sizeLimitedLarge-scale

11. When to Use Each Tool

Use Spreadsheets When:

  • Dataset is small.
  • Quick exploration is needed.
  • Visual formatting matters.
  • Ad hoc analysis is sufficient.

Use SQL When:

  • Dataset is large.
  • Data resides in database.
  • Aggregation across millions of rows is required.
  • Multi-table joins are needed.

12. Order of Operations

Both SQL and spreadsheets follow standard mathematical precedence:

  1. Parentheses
  2. Multiplication/Division
  3. Addition/Subtraction

Always use parentheses when logic must be explicit.


13. Practical Insight

Example business calculation:

Revenue formula:

SELECT quantity * unit_price AS revenue
FROM sales;

Profit formula:

SELECT quantity * unit_price * margin AS profit
FROM sales;

SQL allows these calculations at scale across millions of rows instantly.


14. Summary

Key takeaways:

  • Arithmetic operators behave the same in spreadsheets and SQL.
  • SQL uses SELECT to compute derived columns.
  • Parentheses control calculation order.
  • Modulo operator % returns remainders.
  • Aggregate functions (SUM, AVG) operate across rows.
  • SQL calculations scale to large datasets.
  • Understanding both environments increases analytical flexibility.

Mastery of arithmetic operations across tools strengthens foundational analytical skills and prepares analysts for more advanced aggregation and modeling.