DEV Community

Ali Hamza
Ali Hamza

Posted on

Day 81 of Learning MERN Stack

Hello Dev Community! 👋

It is officially Day 81 of my 100-day full-stack engineering run! Yesterday, I locked down linear logical operators to sweep across singular tabular records. Today, I stepped into the world of database analytics and reporting architectures by mastering: The GROUP BY Clause, the HAVING Clause, and Categorical Data Aggregations! 📊📈

When processing e-commerce telemetry (like counting orders per category) or handling payment services (like tracking successful transactions per payment channel), you cannot just inspect flat datasets. You must condense rows into meaningful summaries. Today, I built exactly that.


🧠 Relational Insights: Organizing Sets on Day 81

As visible in my workspace metrics inside "Screenshot (181).png", I configured a sample transaction model named banking to parse multi-variable row groupings through a three-tier optimization layer:

1. Categorical Segments via GROUP BY

Instead of aggregating the entire column into a single output, GROUP BY acts like a bucket system. Grouping by mode or city automatically splits matching row types and executes aggregate math natively inside independent categories (e.g., counting users per specific transaction channel).

2. Multi-Tier Sorting Layer (ORDER BY with Aggregates)

I combined categorization with metric sequencing arrays (visible on line 24 of "Screenshot (181).png"). By structuring GROUP BY city ORDER BY count(customer) ASC;, the system segments target metrics first and seamlessly sorts the summarized locations from lowest traffic density to highest.

3. Aggregation Filter Constraints (HAVING Clause)

One of the most critical structural paradigms I learned today: The standard WHERE clause cannot filter aggregate functions.

  • WHERE evaluates records before groupings are formed.
  • To filter summarized buckets (e.g., retrieving payment channels that processed 3 or more transactions), we utilize the HAVING clause:

sql
SELECT mode, count(customer) 
FROM banking 
GROUP BY mode 
HAVING count(customer) >= 3;
Enter fullscreen mode Exit fullscreen mode

Top comments (0)