SQLMarrow / Course Academy Experience

SQL & Databases Masterclass Course

Welcome to the ultimate postgresql tutorial for beginners 2026. Work through interactive sql practice problems with solutions, master our comprehensive sql window functions tutorial modules, and prepare for tough sql interview questions at Google and Amazon entirely in your browser. Claim your course completion XP and build production-ready database mastery today!

COURSE PROGRESS
0%
0 of 40 Modules Solved
COURSE SYLLABUS
40 Lessons
LESSON WORKSPACEIntermediate

SQL Lesson 9: Queries with expressions

Introduction & Core Concept

SQL is not just a data retrieval engine; it is a high-speed mathematical calculation engine. You can execute arithmetic operators (+, -, *, /) directly on numeric attributes during query execution to derive new insights instantly.

SELECT salary, salary * 1.10 AS salary_with_ten_percent_raise 
FROM employees;

You can also leverage built-in mathematical functions like ROUND(value, decimal_places) to keep floating-point currency outputs beautifully formatted.

Why & Where We Use It
  • Why We Use It: Computing formulas inside SQL is incredibly efficient. It allows you to output finished, presentation-ready metrics (like profit margins or tax deductions) without writing secondary post-processing code in Python or Excel.
  • Where We Use It: Calculating retail sales taxes, applying corporate discounts, estimating annual interest yields, and converting currency exchange rates.
  • Real-World Example

    The finance department at ApexBank wants to forecast the annual interest expenses payable on all active customer loans. They multiply the loan balance by the interest rate percentage divided by 100, rounding the final cost to two decimal places.

    Best Practices: What to Do & What NOT to Do
  • What to Do: Always ensure floating-point division by appending a .0 to integers (e.g., rate / 100.0). In some SQL engines, dividing two integers performs integer division, silently dropping fractional decimal remainders!
  • What NOT to Do: Never divide by a column without safeguarding against potential zeros. Dividing by zero will instantly crash your query execution! Use defensive logic like NULLIF(divisor_column, 0).
  • Syntax & Pro Tips
    SELECT 
      loan_amount, 
      interest_rate, 
      ROUND(loan_amount * (interest_rate / 100.0), 2) AS annual_interest_payable
    FROM bank_loans;
    Interactive Sandboxed Terminal (Preloaded DB Schema: APEXBANK)
    SQL Query WorkspaceSQLite v3.45 (WASM Mode)
    QUICK INSERT:
    1