Skip to content

Commit a3f2d73

Browse files
Create 3_date_range_exploration.sql
1 parent 8e9dec6 commit a3f2d73

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/*
2+
===============================================================================
3+
Date Range Exploration
4+
===============================================================================
5+
Purpose:
6+
- To determine the temporal boundaries of key data points.
7+
- To understand the range of historical data.
8+
9+
SQL Functions Used:
10+
- MIN(), MAX(), DATEDIFF()
11+
===============================================================================
12+
*/
13+
14+
-- Determine the first and last order date and the total duration in months
15+
SELECT
16+
MIN(order_date) AS first_order_date,
17+
MAX(order_date) AS last_order_date,
18+
DATEDIFF(MONTH, MIN(order_date), MAX(order_date)) AS order_range_months
19+
FROM gold.fact_sales;
20+
21+
-- Find the youngest and oldest customer based on birthdate
22+
SELECT
23+
MIN(birthdate) AS oldest_birthdate,
24+
DATEDIFF(YEAR, MIN(birthdate), GETDATE()) AS oldest_age,
25+
MAX(birthdate) AS youngest_birthdate,
26+
DATEDIFF(YEAR, MAX(birthdate), GETDATE()) AS youngest_age
27+
FROM gold.dim_customers;

0 commit comments

Comments
 (0)