Skip to main content

Command Palette

Search for a command to run...

๐Ÿš€ Using GROUP BY in Oracle SQL for Data Analysis

Updated
โ€ข2 min read
๐Ÿš€ 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 BY

  • Perform 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.

4 views

More from this blog

๏ฟฝ

๐Ÿš€ Getting Started with Oracle Autonomous Database (Free Tier) โ€“ My First Hands-on Experience

15 posts