Written by students who passed Immediately available after payment Read online or as PDF Wrong document? Swap it for free 4.6 TrustPilot
logo-home
Class notes

DBMS

Rating
-
Sold
-
Pages
3
Uploaded on
12-01-2025
Written in
2024/2025

A *Database Management System (DBMS)* is software that organizes, stores, manages, and retrieves data efficiently. It ensures data integrity, security, and consistency while supporting concurrent access and complex queries.

Institution
Course

Content preview

*Grouping and Having Clauses in SQL*

In this chapter, we will learn about the *GROUP BY* and *HAVING* clauses in SQL. These
clauses allow us to group data and perform aggregations, as well as filter the results based
on those aggregations.

---

*GROUP BY Clause*

The *GROUP BY* clause is used to group rows that have the same values in specified
columns into summary rows, often used with aggregate functions (like *SUM()*, *AVG()*,
*COUNT()*, etc.). This enables us to perform aggregations on each group of data rather
than on individual rows.

Example: Grouping Sales Data by Salesperson

Suppose we have a table of *sales_data*, and we want to calculate the total sales for each
salesperson. We can use the *SUM()* function along with the *GROUP BY* clause to
achieve this:

```sql
SELECT salesperson, SUM(sales) AS total_sales
FROM sales_data
GROUP BY salesperson;
```

*Result:*

| salesperson | total_sales |
|-------------|-------------|
| John | 5000 |
| Jane | 7000 |
| Bob | 3000 |

Here, the data is grouped by *salesperson*, and the *SUM()* function calculates the total
sales for each salesperson.

---

*HAVING Clause*

The *HAVING* clause is used to filter groups based on the result of an aggregation. It is
similar to the *WHERE* clause, but while *WHERE* filters rows before aggregation,
*HAVING* filters groups after the aggregation.

Example: Filtering Salespeople with Total Sales Greater Than 4000

Written for

Institution
Course

Document information

Uploaded on
January 12, 2025
Number of pages
3
Written in
2024/2025
Type
Class notes
Professor(s)
Guru
Contains
All classes

Subjects

$10.99
Get access to the full document:

Wrong document? Swap it for free Within 14 days of purchase and before downloading, you can choose a different document. You can simply spend the amount again.
Written by students who passed
Immediately available after payment
Read online or as PDF

Get to know the seller
Seller avatar
janannikesavan30

Also available in package deal

Get to know the seller

Seller avatar
janannikesavan30 If you want to speak fluently, then you have to work on your habits first. Your habits are what make you, and if anything is stopping you from achieving your dreams, it\'s your habits. It\'s not just about what you think
Follow You need to be logged in order to follow users or courses
Sold
-
Member since
1 year
Number of followers
0
Documents
10
Last sold
-

0.0

0 reviews

5
0
4
0
3
0
2
0
1
0

Recently viewed by you

Why students choose Stuvia

Created by fellow students, verified by reviews

Quality you can trust: written by students who passed their tests and reviewed by others who've used these notes.

Didn't get what you expected? Choose another document

No worries! You can instantly pick a different document that better fits what you're looking for.

Pay as you like, start learning right away

No subscription, no commitments. Pay the way you're used to via credit card and download your PDF document instantly.

Student with book image

“Bought, downloaded, and aced it. It really can be that simple.”

Alisha Student

Working on your references?

Create accurate citations in APA, MLA and Harvard with our free citation generator.

Working on your references?

Frequently asked questions