FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
sql-ultimate-course/scripts/13_Aggregate_Functions.sql at main · Vevek-github/sql-ultimate-course · GitHub
Vevek-github
/
sql-ultimate-course
Public
forked from
DataWithBaraa/sql-ultimate-course
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
sql-ultimate-course
/
scripts
/
13_Aggregate_Functions.sql
Copy path
More file actions
More file actions
Latest commit
History
History
History
56 lines (47 loc) · 1.77 KB
Breadcrumbs
sql-ultimate-course
/
scripts
/
13_Aggregate_Functions.sql
Copy path
File metadata and controls
56 lines (47 loc) · 1.77 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/*
==============================================================================
SQL Aggregate Functions
-------------------------------------------------------------------------------
This document provides an overview of SQL aggregate functions, which allow
performing calculations on multiple rows of data to generate summary results.
Table of Contents:
1. Basic Aggregate Functions
- COUNT
- SUM
- AVG
- MAX
- MIN
2. Grouped Aggregations
- GROUP BY
=================================================================================
*/
/*
==============================================================================
BASIC AGGREGATE FUNCTIONS
===============================================================================
*/
--
Find the total number of customers
SELECT
COUNT
(
*
)
AS
total_customers
FROM
customers
--
Find the total sales of all orders
SELECT
SUM
(sales)
AS
total_sales
FROM
orders
--
Find the average sales of all orders
SELECT
AVG
(sales)
AS
avg_sales
FROM
orders
--
Find the highest score among customers
SELECT
MAX
(score)
AS
max_score
FROM
customers
--
Find the lowest score among customers
SELECT
MIN
(score)
AS
min_score
FROM
customers
/*
==============================================================================
GROUPED AGGREGATIONS - GROUP BY
===============================================================================
*/
--
Find the number of orders, total sales, average sales, highest sales, and lowest sales per customer
SELECT
customer_id,
COUNT
(
*
)
AS
total_orders,
SUM
(sales)
AS
total_sales,
AVG
(sales)
AS
avg_sales,
MAX
(sales)
AS
highest_sales,
MIN
(sales)
AS
lowest_sales
FROM
orders
GROUP BY
customer_id
Back
|
FazBrowse Home
|
New Git URL