I hope non equi join is clear now to everyone. Let me know which solution you think should be mentos zindagi 😎 Dont forget to like the videos 🙏
@DataAnalyst2512 ай бұрын
Thank you ankit bhai
@mzeeshans582 ай бұрын
great , I am working on SQL for 10 years but unaware of sol2 logic...Thanks for the precious share
@ankitbansal62 ай бұрын
Glad it was helpful!
@deepeshmatkati30582 ай бұрын
Another interesting concept added to goldmine
@user-dw4zx2rn9v2 ай бұрын
You can use this dummy data for solving the question: CREATE TABLE covid_cases ( record_date DATE PRIMARY KEY, cases_count INT ); INSERT INTO covid_cases (record_date, cases_count) VALUES ('2021-01-01',66),('2021-01-02',41),('2021-01-03',54),('2021-01-04',68),('2021-01-05',16),('2021-01-06',90),('2021-01-07',34),('2021-01-08',84),('2021-01-09',71),('2021-01-10',14),('2021-01-11',48),('2021-01-12',72),('2021-01-13',55), ('2021-02-01',38),('2021-02-02',57),('2021-02-03',42),('2021-02-04',61),('2021-02-05',25),('2021-02-06',78),('2021-02-07',33),('2021-02-08',93),('2021-02-09',62),('2021-02-10',15),('2021-02-11',52),('2021-02-12',76),('2021-02-13',45), ('2021-03-01',27),('2021-03-02',47),('2021-03-03',36),('2021-03-04',64),('2021-03-05',29),('2021-03-06',81),('2021-03-07',32),('2021-03-08',89),('2021-03-09',63),('2021-03-10',19),('2021-03-11',53),('2021-03-12',78),('2021-03-13',49), ('2021-04-01',39),('2021-04-02',58),('2021-04-03',44),('2021-04-04',65),('2021-04-05',30),('2021-04-06',87),('2021-04-07',37),('2021-04-08',95),('2021-04-09',60),('2021-04-10',13),('2021-04-11',50),('2021-04-12',74),('2021-04-13',46), ('2021-05-01',28),('2021-05-02',49),('2021-05-03',35),('2021-05-04',67),('2021-05-05',26),('2021-05-06',82),('2021-05-07',31),('2021-05-08',92),('2021-05-09',61),('2021-05-10',18),('2021-05-11',54),('2021-05-12',79),('2021-05-13',51), ('2021-06-01',40),('2021-06-02',59),('2021-06-03',43),('2021-06-04',66),('2021-06-05',27),('2021-06-06',85),('2021-06-07',38),('2021-06-08',94),('2021-06-09',64),('2021-06-10',17),('2021-06-11',55),('2021-06-12',77),('2021-06-13',48), ('2021-07-01',34),('2021-07-02',50),('2021-07-03',37),('2021-07-04',69),('2021-07-05',32),('2021-07-06',80),('2021-07-07',33),('2021-07-08',88),('2021-07-09',57),('2021-07-10',21),('2021-07-11',56),('2021-07-12',73),('2021-07-13',42), ('2021-08-01',41),('2021-08-02',53),('2021-08-03',39),('2021-08-04',62),('2021-08-05',23),('2021-08-06',83),('2021-08-07',29),('2021-08-08',91),('2021-08-09',59),('2021-08-10',22),('2021-08-11',51),('2021-08-12',75),('2021-08-13',44), ('2021-09-01',36),('2021-09-02',45),('2021-09-03',40),('2021-09-04',68),('2021-09-05',28),('2021-09-06',84),('2021-09-07',30),('2021-09-08',90),('2021-09-09',61),('2021-09-10',20),('2021-09-11',52),('2021-09-12',71),('2021-09-13',43), ('2021-10-01',46),('2021-10-02',58),('2021-10-03',41),('2021-10-04',63),('2021-10-05',24),('2021-10-06',82),('2021-10-07',34),('2021-10-08',86),('2021-10-09',56),('2021-10-10',14),('2021-10-11',57),('2021-10-12',70),('2021-10-13',47), ('2021-11-01',31),('2021-11-02',44),('2021-11-03',38),('2021-11-04',67),('2021-11-05',22),('2021-11-06',79),('2021-11-07',32),('2021-11-08',94),('2021-11-09',60),('2021-11-10',15),('2021-11-11',54),('2021-11-12',73),('2021-11-13',46), ('2021-12-01',29),('2021-12-02',50),('2021-12-03',42),('2021-12-04',65),('2021-12-05',25),('2021-12-06',83),('2021-12-07',30),('2021-12-08',93),('2021-12-09',58),('2021-12-10',19),('2021-12-11',52),('2021-12-12',75),('2021-12-13',48);
@atharwaborkar6778Ай бұрын
Thank you So much For This
@ishitasrivastava59232 ай бұрын
Keep coming up with awesome content ! Looking forward to seeing Python questions too for data profiles like you come up with the SQL ones
@ankitbansal62 ай бұрын
More to come!
@ramakumarguntamadugu129927 күн бұрын
Great content and explanation as Always 👍
@mohdtoufique37862 ай бұрын
Hi Ankit! Thanks for the content My approach WITH month_cases AS( SELECT (month(record_date)) AS month_no, sum(covid_cases) as month_cases FROM covid_data GROUP BY month(record_date)) SELECT a.month_no,a.month_cases AS curr_month_cases, sum((b.month_cases)) AS prior_month_cases, a.month_cases*100.0/sum((b.month_cases)) AS mom_increase FROM month_cases a left join month_cases b ON a.month_no>b.month_no GROUP BY a.month_no,a.month_cases
@healthyhome-padhu31052 ай бұрын
Awesome approach. U have dissected it so nicely. In love with your content
@ankitbansal62 ай бұрын
Glad to hear that
@Datapassenger_prashant2 ай бұрын
Amazing amazing ❤❤❤
@sravankumar17672 ай бұрын
Superb explanation 👌 👏 👍
@ankitbansal62 ай бұрын
Thank you 🙂
@rk-ej9ep2 ай бұрын
Awesome..🤜
@ankitbansal62 ай бұрын
Thank you! Cheers!
@abdulqadar559Ай бұрын
Hi Ankit, I have been following your videos from so long and I am happy to say that I solved it using advanced aggregation in the first go.
@ankitbansal6Ай бұрын
Excellent!!
@azadshaik51332 ай бұрын
Very well explained👏
@ankitbansal62 ай бұрын
Thank you 🙂
@user-dw4zx2rn9v2 ай бұрын
Mysql solution: with cte as ( select month(record_date) as mth , sum(cases_count) as Total_cases from covid_cases group by month(record_date) ) , cte2 as ( select mth, total_cases, sum(total_cases) over (order by mth rows between unbounded preceding and current row) as cul_sum, lag(total_cases,1,0) over (order by mth) as prev_cases, (sum(total_cases) over (order by mth rows between unbounded preceding and current row)) - Total_cases as diff from cte ) select mth, total_cases, diff, Round(100*(total_cases/diff),2) as Percentage_change from cte2
@arvindkr9742 ай бұрын
If you cast the "percent_inc" column as decimal(10,1) then the final result looks exactly same as the hackerrank's output !
@rahulmehla20142 ай бұрын
Interesting concept Ankit, You are a blessing for the people like us who are preparing for data science domain jobs. God bless you
@ankitbansal62 ай бұрын
Thanks a ton🙏
@vishwassharma33122 ай бұрын
Method 2 was fentastic
@rushikeshwaghmare34462 ай бұрын
Thank you Sir…I have attended this exam…even chatgpt didn’t helped me to solve this question. You are great!! Please can you make one separate video on advanced aggregation and its use cases?
@ankitbansal62 ай бұрын
Here you go kzfaq.info/get/bejne/a6-Xm82Ql7arhmQ.html
@shivangirai3200Ай бұрын
Nice Explanation. Could you please upload some videos about stored procedures if possible.
@ankitbansal6Ай бұрын
Sure I will
@DeepakKumar-mg8rvАй бұрын
Instead month number can it be sorted as per month name?
@nitinsharma2019Ай бұрын
Please provide the dataset as well
@tusharraheja67182 ай бұрын
Hey Ankit, amazing explanation! Could you please share the entire dataset in the description box? The video shows you have dataset for all days in the year. However the description box dataset has only 13 rows.
@ankitbansal62 ай бұрын
There is a character limit so it can't be put full. You can create similar data for 365 days yourself
@tusharraheja67182 ай бұрын
Thanks for acknowledging, Ankit. Didn’t know about this limit.
@shivukaraguppi69842 ай бұрын
@@ankitbansal6 can u share file link in desc?
@ankitbansal62 ай бұрын
@@shivukaraguppi6984 you can just use the sample data and generate the 365 days data in Excel by dragging. Data need not be exactly same :)
@tanujitroyАй бұрын
Hi Ankit, Thanks for sharing such solutions. Here is my solution to this problem: WITH monthly_cases AS ( SELECT MONTH(record_date) AS Month, SUM(cases_count) AS Monthly_Cases FROM daily_cases GROUP BY MONTH(record_date) ), Cumulative_Case AS ( SELECT Month, Monthly_Cases, SUM(Monthly_Cases) OVER (ORDER BY Month) AS Cumulative_Cases FROM monthly_cases ) SELECT Month, Monthly_Cases, Cumulative_Cases, (Monthly_Cases / LAG(Cumulative_Cases) OVER (ORDER BY Month)) * 100 AS Percent_Increase FROM Cumulative_Case; Please let me know if this will work or not. Thank You!
@jawakar8266Ай бұрын
Thanks for the great content, loved your explanation! Are there any drawbacks in using the method - 2 advanced aggregation?
@ankitbansal6Ай бұрын
Nope. It's actually better.
@user-dk4xj5ub9q11 күн бұрын
@ankitbansal6 sir please paste the script in the description or comments or provide a link.. so that it would be easy for the learners to practice. thank you
@viswa61262 ай бұрын
Thanks for the explanation. Can you update the complete dataset in the description?
@ankitbansal62 ай бұрын
There is a character limit. You can create some data for 365 days.
@kailashpatro57682 ай бұрын
with cte as ( select month(record_date) as month, sum(cases_count) as total from covid_cases group by day(record_date) ) , cte2 as ( select month, total,sum(total) over(order by month rows between unbounded preceding and 1 preceding) as rnk from cte ) select month,total, (0.1*total/rnk ) from cte2
@kailashpatro57682 ай бұрын
I am in love with your SQL videos thankyou so much sir
@Akhil_S_N2 ай бұрын
Well explained sir! Can we use alias name in the group by instead of using the same select function? Would like to get educated on this
@ankitbansal62 ай бұрын
Nope . group by runs before select
@nagarajupullur64892 күн бұрын
brother iam not able to find problem code in discription
@captainsaver692 ай бұрын
Amazing video! Every day, I try to solve at least one SQL problem from your videos. Thank you for your hard work. It would be fantastic if you could also begin a Python series.
@ankitbansal62 ай бұрын
Great suggestion!
@sanrhn2 ай бұрын
Yes Ankit. for python we are not getting deep problem solving analysis like you did for SQL
@sraoarjun2 ай бұрын
Yes I second that , kindly do come up with a similar Python series and that will be truly helpful
@ankitbansal62 ай бұрын
@@sanrhn for python is it coding or pandas questions ?
@captainsaver692 ай бұрын
@@ankitbansal6 Every question that is important from an interview perspective. The rest I believe can be learned on the job.
@atharwaborkar6778Ай бұрын
Hi Ankit , Please give us the schema as well for the Questions. So that we can Solve it.
@ankitbansal6Ай бұрын
Description box
@shubhamravikar60292 ай бұрын
@ankitbansal great leaning from you may I get the dataset of this question or you can please let me know where can I get the dataset of this question so that I can practice this.
@ankitbansal62 ай бұрын
Description box
@Ashu23200Ай бұрын
No insert script
@ZaidJafri2 ай бұрын
I was asked a similar question yesterday during my 1st technical round for BIE with Amazon and I failed miserably 😭😭😭😭 I wish this was uploaded couple of days ago!
@ankitbansal62 ай бұрын
Better luck next time 😊
@tejas40542 ай бұрын
Ye IT wale kuch bbi puchte hai jaise in sabko lagta hai ki hamara dimaag Einstein jaisa hai,,,, khud interviewer ko kych nhi aata aur hamse Einstein jaisi umeed rekhte hai
@NarasimhanSadasivam2 ай бұрын
@Ankit--- can you please share the data set, thanks
@ankitbansal62 ай бұрын
Description box
@PM-ps5poАй бұрын
what if we would have used "Rows between Unbounded preceding and current row" here.🤔
@ankitbansal6Ай бұрын
Then it will be till current month not prior month
@dibyashreechowdhury45992 ай бұрын
Hi, I tried solving this question today in hackerrank test by meesho but couldn't get the result in ms sql server . can you please check?? by the first method of non equi join.
@mohitgour1990Ай бұрын
Yes today also i tried solving the same question in Meesho test with the second approach, still in hackerrank , although the output matched, it did not passed the test cases just because of the headers of "month","percent_increase".
@m04d10y19962 ай бұрын
what if we have multiple year data, here we assumed that the data is of same year.
@ankitbansal62 ай бұрын
Then you just need to use the year also in join for the first solution . In the second you need to add year in order by before month
@udayakumark10792 ай бұрын
Please attach DDL
@ankitbansal62 ай бұрын
Description box
@proud_indian01612 ай бұрын
@@ankitbansal6 not complete
@Techie-Harry2 ай бұрын
I have another meesho sql question, Can you solve it
@ankitbansal62 ай бұрын
Send it to sql.namaste@gmail.com
@Techie-Harry2 ай бұрын
@@ankitbansal6 Sent Questions
@Techie-Harry2 ай бұрын
please check
@ankitbansal62 ай бұрын
@@Techie-Harry Got it
@Techie-Harry2 ай бұрын
@@ankitbansal6 will you post video on these question
@Apna_tahlka_1232 ай бұрын
Data ya pdf bhi provide Kia karo plj
@ankitbansal62 ай бұрын
Description box
@AmanVerma-cu3lpАй бұрын
Run the below script to create table and insert sample data. CREATE TABLE covid_cases ( record_date DATE PRIMARY KEY, cases_count INT ); DECLARE @end_date date; DECLARE @loop_date date; DECLARE @num INT; set @end_date = '2021-12-31' set @loop_date = '2021-01-01' WHILE @loop_date
@AmanVerma-cu3lpАй бұрын
My solution in MS SQL Server: with cte as( select year(record_date) year, format(record_date, 'MMM') month, Datepart(month, record_date) month_no, sum(cases_count) total_cases from covid_cases group by year(record_date), format(record_date, 'MMM'), Datepart(month, record_date)), cte2 as( select year, month, total_cases, coalesce(sum(total_cases) over(order by year, month_no rows between unbounded preceding and 1 preceding), 0) as rolling_sum from cte) select concat_ws('-', year, month) month, total_cases, IIF(rolling_sum = 0, 0, cast(100*total_cases/cast(rolling_sum as float) as decimal(10,1))) as percentage from cte2