Building Calendar Dimension Table from Scratch with SQL | SQL For Analytics

  Рет қаралды 15,595

Ankit Bansal

Ankit Bansal

Күн бұрын

In this video we are going to create a calendar dimension table from scratch. It is a very important video as calendar table has many use cases and I will be using this table in many of my future videos.
Here is the script to get very first row :
select cast('2000-01-01' as date) as cal_date
,datepart(year,'2000-01-01') as cal_year
,datepart(dayofyear, '2000-01-01') as cal_year_day
,datepart(quarter, '2000-01-01') as cal_quarter
,datepart(month, '2000-01-01') as cal_month
,datename(month, '2000-01-01') as cal_month_name
,datepart(day, '2000-01-01') as cal_month_day
,datepart(week, '2000-01-01') as cal_week
,datepart(weekday, '2000-01-01') as cal_week_day
,datename(weekday, '2000-01-01') as cal_day_name
Start your analytics journey : www.namastesql.com/
Zero to hero(Advance) SQL Aggregation:
• All About SQL Aggregat...
Most Asked Join Based Interview Question:
• Most Asked SQL JOIN ba...
Solving 4 Trick SQL problems:
• Solving 4 Tricky SQL P...
Data Analyst Spotify Case Study:
• Data Analyst Spotify C...
Top 10 SQL interview Questions:
• Top 10 SQL interview Q...
Interview Question based on FULL OUTER JOIN:
• SQL Interview Question...
Playlist to master SQL :
• Complex SQL Questions ...
Rank, Dense_Rank and Row_Number:
• RANK, DENSE_RANK, ROW_...
#sql #dataengineer #calendar

Пікірлер: 29
@zeeshanazeem5212
@zeeshanazeem5212 4 ай бұрын
Ankit Bhai, boht barhya kaam kiya hai... 2 months se dhoondh raha tha. Itnay din se yeh video kidhar th bhayya. Thanks ❤
@harshaltare119
@harshaltare119 4 ай бұрын
So excited for the upcoming query questions related to this calendar dimension table.
@shoibazareen4489
@shoibazareen4489 4 ай бұрын
Thanks for creating the data engineering videos, I love your explanation. Good luck sir
@Ashu23200
@Ashu23200 2 ай бұрын
you blown my mind. god bless another god of sql.
@srinubathina7191
@srinubathina7191 4 ай бұрын
Thank You Bro Super explanation. I am learning very good stuff from you
@iamkiri_
@iamkiri_ 4 ай бұрын
you are the man ... Always great content -:)
@rockagain5416
@rockagain5416 4 ай бұрын
Very good Logic ❤❤❤
@Justin2k20
@Justin2k20 4 ай бұрын
Thank you Ankit 🙏🏻
@gayatri7536
@gayatri7536 4 ай бұрын
Thankyou it's really superb 👏👏
@ankitbansal6
@ankitbansal6 4 ай бұрын
Welcome 😊
@nandan7755
@nandan7755 4 ай бұрын
Nice explanation dates functions Ankit bhaiya ❤❤🎉🎉
@SagarKumar-hh8kt
@SagarKumar-hh8kt 4 ай бұрын
Can you explain me what is the use of in joining of two table or in self join?
@AamerSuhail
@AamerSuhail 4 ай бұрын
No more distraction.. Just stick to Ankit Bhansal YT channel for SQL & thanks me later 😅
@Ashu23200
@Ashu23200 2 ай бұрын
absolute true
@GSK_G17
@GSK_G17 4 ай бұрын
Hi Ankit, it is a great learning, I have been following you from the beginning, would you please implement day light saving logic in the where condition, ex: my views delivering the report every 1 hour to the business
@ankitbansal6
@ankitbansal6 4 ай бұрын
What exactly do you want please explain
@0099kunal1
@0099kunal1 4 ай бұрын
Hey Ankit are we considering leap year also in the calendar?
@ankitbansal6
@ankitbansal6 4 ай бұрын
Yes absolutely
@deepeshmatkati3058
@deepeshmatkati3058 4 ай бұрын
Perfect explanation
@ankitbansal6
@ankitbansal6 4 ай бұрын
Thank you 😊
@shivammishra-mk9jp
@shivammishra-mk9jp 10 күн бұрын
Hey Ankit, Can you please help me with how to create this dimension table in mysql I am done with all the script following your video but I got stuck at last point when we need to create the physical table. This query is not working in mysql....please help. SELECT row_number() over(order by cal_date asc) as id , * into calendar_dimension from cte ; SET SESSION cte_max_recursion_depth = 1000000; Thanks in advance
@ankitbansal6
@ankitbansal6 10 күн бұрын
Use create table as instead of into
@shristisrivastava1324
@shristisrivastava1324 4 ай бұрын
Please make a video on subquery. I am not able to understand how to solve subqueries problem. I tried a lot from different different resources but not able to solve it . And if there is any cheat method for this then also please share. Thankyou
@prasannaeega7459
@prasannaeega7459 4 ай бұрын
S plz share
@KrishnaVermaAnalytics
@KrishnaVermaAnalytics 4 ай бұрын
I tried to make a calendar table in MySQL: SET cte_max_recursion_depth=30000; with recursive cte as (select cast('2000-01-01' as date) as cal_date ,year('2000-01-01') as cal_year ,dayofyear('2000-01-01') as cal_year_day ,quarter('2000-01-01') as cal_quarter ,month('2000-01-01') as cal_month ,monthname('2000-01-01') as cal_month_name ,day('2000-01-01') as cal_month_day ,week('2000-01-01') as cal_week ,weekday('2000-01-01') as cal_week_day ,dayname('2000-01-01') as cal_day_name union all select date_add(cal_date, interval 1 day) as cal_date, year(date_add(cal_date, interval 1 day)) as cal_year, dayofyear(date_add(cal_date, interval 1 day)) as cal_year_day, quarter(date_add(cal_date, interval 1 day)) as cal_quarter, month(date_add(cal_date, interval 1 day)) as cal_month, monthname(date_add(cal_date, interval 1 day)) as cal_month_name, day(date_add(cal_date, interval 1 day)) as cal_month_day, week(date_add(cal_date, interval 1 day)) as cal_week, weekday(date_add(cal_date, interval 1 day)) as cal_week_day, dayname(date_add(cal_date, interval 1 day)) as cal_day_name from cte where cal_date < cast('2050-12-31' as date) ) select row_number() over(order by cal_date asc) as rn, cal_date, cal_year, cal_year_day, cal_quarter, cal_month, cal_month_name, cal_month_day, cal_week, cal_week_day, cal_day_name from cte;
@shashanktiwari133
@shashanktiwari133 4 ай бұрын
how have you created dim table using this cte ?
@KrishnaVermaAnalytics
@KrishnaVermaAnalytics 4 ай бұрын
@@shashanktiwari133 it's a recursive cte not just an ordinary cte. it works the same as you apply recursion in any function while coding.
Looks realistic #tiktok
00:22
Анастасия Тарасова
Рет қаралды 101 МЛН
Каха и суп
00:39
К-Media
Рет қаралды 5 МЛН
LOVE LETTER - POPPY PLAYTIME CHAPTER 3 | GH'S ANIMATION
00:15
Don't Fail the Management Round: Essential Tips and Tricks
27:13
KSR Datavizon
Рет қаралды 92 М.