nice approach. I have another doubt: How to use/fill the record for missing dates from the previous dates ? like 10th January is the missing date then how can we make use of values on 9th jan and copy for 10th jan and generate a new table with all the dates ?
Great Solution... I have a requirement: I have a cities column with or without duplicates. I need count of cities start with each alphabet. If there is no city with any alphabet it should be shown as zero. Can you help me out @LearnAtKnowstar ?
@@LearnatKnowstar I wrote a query for firstname in Person.Person table, please lemme know whether my approach is correct or not. With t1 as (select row_number() over(order by object_id) as Alp from sys.columns), t2 as (select char(((Alp-1)%26)+65) alpha from t1 where Alp
Don't, simply create a dates table, every DB should have a dates tables created. Just link to that table. Get a script online and select first 12 days for each month from that table.
Thanks for the video, but I have a small problem when I'm creating dates month wise, its not resulting proper, its adding 30 days to each date, and with this it results this way 2016-12-31 00:00:00.000 2017-01-31 00:00:00.000 2017-02-28 00:00:00.000 2017-03-28 00:00:00.000 Declare @startdate date='2016-12-31'; Declare @endate date ='2022-7-31'; With dates as ( select @startdate as transactiondate union all Select dateadd(mm,1,transactiondate) from dates where dateadd(mm,1,transactiondate)
This is because you're using month (mm) in the datepart for DATEADD fn this will increment the month by the number to add specified. Use dateadd(dd,1, transactiondate) and it will solve your problem.
You are so awesome! SQL came late for me in life but learning all these cool tricks is helping a LOT
Glad it is helpful.
Queen 👑 !
Excellent channel and teaching skills 🏆
Thank you so much for your support!
We can apply having clause count(OrderID) is Null to filter out the missing dates
Superb explanation 👌 👏
Thank you
Every helpful video, nice way of explanation 👍
Thank you 🙏
Awesome content❤
Thank you
nice approach. I have another doubt:
How to use/fill the record for missing dates from the previous dates ?
like 10th January is the missing date then how can we make use of values on 9th jan and copy for 10th jan and generate a new table with all the dates ?
Thank you for your comment. The forward fill approach is the topic for our next video coming this week. Stay tuned and please Subscribe 🙏
We can use lag window function
Great Solution... I have a requirement: I have a cities column with or without duplicates. I need count of cities start with each alphabet. If there is no city with any alphabet it should be shown as zero. Can you help me out @LearnAtKnowstar ?
You can perform a count by extracting first letter of each city..ex - Left(Cityname,1)
Create a CTE with the list of all alphabets A-Z and perform a left join with the CTE on the first alphabet of column city
@@LearnatKnowstar I wrote a query for firstname in Person.Person table, please lemme know whether my approach is correct or not.
With t1 as (select row_number() over(order by object_id) as Alp from sys.columns),
t2 as (select char(((Alp-1)%26)+65) alpha from t1 where Alp
Looks perfect! Only not sure why there is group by on firstname for t3. Other than that, this should be giving the correct results.
Thanks for mentioning this scenario. This is an interesting idea for us to cover in our video tutorials!
Nice explained 💐
Thank you
A CTE is not the same as a temporary table. It just isn't.
Ty mam...
Thank you
Thanks
Thank You!
Can you please share the scripts of this example?
Hi, Please explain to create temp table with first 12 days in each month of a year
Don't, simply create a dates table, every DB should have a dates tables created.
Just link to that table. Get a script online and select first 12 days for each month from that table.
Super stuff
Thank you
Thanks for the video, but I have a small problem when I'm creating dates month wise, its not resulting proper, its adding 30 days to each date, and with this it results this way
2016-12-31 00:00:00.000
2017-01-31 00:00:00.000
2017-02-28 00:00:00.000
2017-03-28 00:00:00.000
Declare @startdate date='2016-12-31';
Declare @endate date ='2022-7-31';
With dates as
(
select @startdate as transactiondate
union all
Select dateadd(mm,1,transactiondate)
from dates
where dateadd(mm,1,transactiondate)
This is because you're using month (mm) in the datepart for DATEADD fn this will increment the month by the number to add specified.
Use dateadd(dd,1, transactiondate) and it will solve your problem.
Sequence generation is very easy in MySQL: SELECT seq FROM seq_1_to_31
How to find duplicate data without using Group by clause
Maximum recursion = 100, a longer sequence can't be generated.
The value can be changed by specifying MAXRECURSION: SELECT OrderDate from Dates OPTION (MAXRECURSION NNN);
MAXRECURSION >= 0 and
Where was this video 3 months ago. I came to a similar solution but I was struggling as a newbie.
Glad it was helpful.
it is doesn't work in MySQL.
Thanks
Thank you