Posts

Showing posts from December, 2025

SQL Aggregate Functions

SQL Aggregate Functions: Overview and Usage Aggregate functions in SQL are used to perform calculations on multiple rows of a table and return a single result. They are most commonly used with the SELECT statement to summarize data. When to Use Aggregate Functions? Use aggregate functions when you want to get an overview or summary from your data, such as totals, averages, counts, minimums, or maximums. Common Types of Aggregate Functions 1. COUNT() Purpose: Counts the number of rows that match a specified condition or counts non-null values in a column. Example: SELECT COUNT(NAME) FROM EMPLOYEE; 2. SUM() Purpose: Adds up all the numeric values in a specified column. Example: SELECT SUM(SALARY) FROM EMPLOYEE; 3. AVG() Purpose: Calculates the average (mean) of numeric values in a column. Example: SELECT AVG(SALARY) FROM EMPLOYEE; 4. MIN() Purpose: Returns the smallest (minimum) value in a column. Example: SELECT MIN(SALARY) FROM EMPLOYEE; 5. MAX() Purpose: Returns the largest (maximum) ...

Operators in SQL

 Operators in SQL SQL operators are special symbols or keywords used to specify conditions in SQL statements. They help filter, compare, and perform calculations on data in your database queries. Types of operators: 1. Arithmetic Operators: Addition(+), subtraction(-), multiplication(*), division(/) , modulus(%) Used to perform mathematical calculations. + Addition SELECT 2 + 3 AS Result; (Result: 5) - Subtraction SELECT 5 - 2 AS Result; (Result: 3) * Multiplication SELECT 4 * 2 AS Result; (Result: 8) / Division SELECT 10 / 2 AS Result; (Result: 5) % Modulus (Remainder) SELECT 10 % 3 AS Result; (Result: 1) 2. Comparison Operator: equla to(=), not equal to (!=), gt(>) , lt(<), gteq(>=) gtlt(<) Used to compare values in SQL statements. = Equal to SELECT * FROM employee WHERE salary = 50000; <> or != Not equal to SELECT * FROM employee WHERE name <> 'Rahul'; > Greater than SELECT * FROM employee WHERE age > 25; ...