Skip to content

Commit 9e05365

Browse files
committed
edit last few suggestions with sidney's help
1 parent 3955a33 commit 9e05365

File tree

3 files changed

+12
-2
lines changed

3 files changed

+12
-2
lines changed

learn-pr/wwl-azure/basic-sql-aggregate-functions-grouping/includes/3-aggregate-functions.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
Instead of retrieving individual rows, you frequently need to summarize data to understand trends or patterns. Aggregate functions are designed for this purpose, allowing you to perform calculations on a group of rows and return a single result. Common examples include determining the total sales, the average price of products, or the number of orders placed. These functions are fundamental tools for data analysis in SQL.
2+
23
Examples of aggregate functions include `COUNT` to count rows, `SUM` to calculate totals, `AVG` for averages, `MIN` to find the smallest value, and `MAX` to find the largest value in a dataset.
34

45
## COUNT
@@ -8,11 +9,13 @@ Examples of aggregate functions include `COUNT` to count rows, `SUM` to calculat
89
```sql
910
SELECT COUNT(*) FROM sales.orders;
1011
```
12+
1113
The result of this query is a single numeric value representing the total number of orders (or rows) present in the `sales.orders` table.
1214

1315
```sql
1416
SELECT COUNT(DISTINCT country) FROM sales.customers;
1517
```
18+
1619
This SQL query uses the `COUNT` function along with the `DISTINCT` keyword to determine the number of unique countries present in the `country` column of the `sales.customers` table. Essentially, it counts each distinct `country` only once, providing a numerical result that represents the total number of different countries in the dataset.
1720

1821
## SUM
@@ -22,6 +25,7 @@ This SQL query uses the `COUNT` function along with the `DISTINCT` keyword to de
2225
```sql
2326
SELECT SUM(price) FROM sales.products;
2427
```
28+
2529
This query calculates the total sum of all values in the `price` column of the `sales.products` table. It aggregates the prices of multiple rows into a single numeric result, representing the total cost of all products.
2630

2731
## AVG
@@ -31,6 +35,7 @@ The `AVG` function is an essential SQL aggregate function designed to calculate
3135
```sql
3236
SELECT AVG(price) FROM sales.products;
3337
```
38+
3439
This query is designed to calculate the average `price` of all products listed in the `sales.products` table. By using the `AVG` function, it computes the arithmetic mean of the values in the `price` column, effectively summarizing the dataset into a single representative value.
3540

3641
## MAX and MIN
@@ -40,4 +45,5 @@ The `MAX` and `MIN` functions are aggregate functions used to identify the highe
4045
```sql
4146
SELECT MAX(price), MIN(price) FROM sales.products;
4247
```
48+
4349
This query retrieves two values: the highest `price` and the lowest `price` among all products listed in the `sales.products` table.

learn-pr/wwl-azure/basic-sql-aggregate-functions-grouping/includes/4-group-by-having.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
To gain deeper insights and better organize data within a database, SQL introduces the powerful `GROUP BY` and `HAVING` clauses.
1+
To gain deeper insights and better organize data within a database, SQL introduces the powerful `GROUP BY` and `HAVING` clauses.
2+
23
These tools allow you to transform raw data into meaningful summaries by categorizing rows and applying aggregate functions, making it easier to analyze trends, identify patterns, or generate reports tailored to specific categories.
34

45
## GROUP BY
@@ -17,6 +18,7 @@ SELECT category_id, AVG(price)
1718
FROM sales.products
1819
GROUP BY category_id;
1920
```
21+
2022
This query retrieves the average price of products within each category by grouping the rows of the `sales.products` table according to their `category_id`. By applying the `AVG()` function to the `price` column, the query calculates the mean value of prices for all products under every distinct `category_id`.
2123

2224
`GROUP BY` clause doesn't always need to be paired with aggregate functions. While it's commonly used alongside aggregate functions to perform calculations on grouped data, `GROUP BY` can also be used by itself to organize data into groups for other purposes, such as retrieving distinct combinations of columns.
@@ -26,6 +28,7 @@ SELECT category_id
2628
FROM sales.products
2729
GROUP BY category_id;
2830
```
31+
2932
This query groups the rows by `category_id` without performing any aggregation, simply listing each distinct `category_id` present in the `sales.products` table.
3033

3134
## HAVING
@@ -40,4 +43,5 @@ FROM sales.products
4043
GROUP BY category_id
4144
HAVING AVG(price) > 30;
4245
```
46+
4347
This query calculates the average `price` of products within each category by grouping rows of the `sales.products` table according to their `category_id`. It then filters the results to include only those categories where the average `price` exceeds 30 using the `HAVING` clause.

learn-pr/wwl-azure/basic-sql-aggregate-functions-grouping/index.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ products:
166166
subjects:
167167
- databases
168168
units:
169-
- learn.wwl-azure.basic-sql-aggregate-functions-grouping-introduction
169+
- learn.wwl-azure.basic-sql-aggregate-functions-grouping.introduction
170170
- learn.wwl-azure.basic-sql-aggregate-functions-grouping.sample-database-overview
171171
- learn.wwl-azure.basic-sql-aggregate-functions-grouping.aggregate-functions
172172
- learn.wwl-azure.basic-sql-aggregate-functions-grouping.group-by-having

0 commit comments

Comments
 (0)