๐ Using GROUP BY in Oracle SQL for Data Analysis

As part of my continued learning with Oracle Autonomous Database, I explored how to group data using SQL. This is a powerful feature used in real-world applications for data analysis and reporting.
๐ฏ Objective
The goal of this activity was to:
Understand how to group data using
GROUP BYPerform aggregate operations on grouped data
Analyze structured data efficiently
๐ป Step 1: Creating the Table
CREATE TABLE employees (
emp_id NUMBER,
emp_name VARCHAR2(50),
department VARCHAR2(50),
salary NUMBER
);
๐งช Step 2: Inserting Data
INSERT INTO employees VALUES (1, 'Ali', 'IT', 50000);
INSERT INTO employees VALUES (2, 'Ahmed', 'HR', 70000);
INSERT INTO employees VALUES (3, 'Sara', 'IT', 60000);
INSERT INTO employees VALUES (4, 'Zara', 'HR', 65000);
๐ Step 3: Viewing All Records
SELECT * FROM employees;
๐ Step 4: Grouping Data
SELECT department, COUNT(*) AS total_employees
FROM employees
GROUP BY department;
This groups employees by department and counts how many belong to each.
๐ Step 5: Average Salary by Department
SELECT department, AVG(salary) AS avg_salary
FROM employees
GROUP BY department;
This calculates the average salary for each department.
๐ก What I Learned
How to group records using GROUP BY
Combining GROUP BY with aggregate functions
Real-world data analysis using SQL
๐ Conclusion
This activity helped me understand how data can be grouped and analyzed effectively using Oracle SQL. GROUP BY is a key concept in database analytics and reporting.





