SQL For Data Science | NTILE Analytical Function | Top and Bottom N Percent Customers

  Рет қаралды 7,854

Ankit Bansal

Ankit Bansal

Жыл бұрын

In this video we are going to learn a SQL analytical function called NTILE which is used in data science to create customer distribution based on sales. We will use the orders dataset to understand it via solving a problem where we need to find top 25 and bottom 25 percent customers be sales.
here is the orders dataset link:
docs.google.com/spreadsheets/...
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 #datascience #analytics

Пікірлер: 32
@avi8016
@avi8016 Жыл бұрын
Great explanation 💯
@KARAN-xf2it
@KARAN-xf2it 4 ай бұрын
Excellent explanation
@stat_life
@stat_life Жыл бұрын
#SUMMARY #REGION WISE SEGMENTATION OF CUSTOMER ON BASIS OF TOTAL SALES --NTILE(x) : It is a window function which divides the entire dataset into x percentiles on basis of windows. #### MS SQL #### WITH testcase AS ( SELECT customer_name, region, SUM(sales) as total_sales FROM orders GROUP BY customer_name, region ORDER BY region, total_sales DESC ) SELECT *, NTILE(4) OVER(PARTITION BY region ORDER BY SUM(SALES) DESC) AS segment FROM testcase
@sachinkv6972
@sachinkv6972 Ай бұрын
SUPER BRO
@shubhammeshram8504
@shubhammeshram8504 Жыл бұрын
excellent..
@harinee7251
@harinee7251 Жыл бұрын
Thank you so much sir
@kadhaisollaporom9040
@kadhaisollaporom9040 Жыл бұрын
Thankyou for these videos its really helpful for the aspiring data professionals thankyou ❤
@ankitbansal6
@ankitbansal6 Жыл бұрын
My pleasure 😊
@harinee7251
@harinee7251 Жыл бұрын
Sir , kindly can you provide a detailed roadmap of how to become a data engineer..it will be very useful
@muditmishra9908
@muditmishra9908 Жыл бұрын
We can also use : PERCENTILE_CONT() function followed by where clause.
@Satscool786
@Satscool786 Жыл бұрын
Ankit bhai thanku for all the videos u are providing here, really helpful Just wanted to confirm that the python course u have on namstesql also covers numpy pandas or other data analysis part? And do u also help in resume creation n all ?
@ankitbansal6
@ankitbansal6 Жыл бұрын
Yes numpy pandas are covered
@ankitsaxena565
@ankitsaxena565 Жыл бұрын
Nice explanation 🙏
@ankitbansal6
@ankitbansal6 Жыл бұрын
Keep watching
@ur8946
@ur8946 Жыл бұрын
How you come to number 4 for NTile ?
@sindhujajittuka9020
@sindhujajittuka9020 Жыл бұрын
Suppose we have a table with column name hiredate (format yyyy-mm-dd) We need to find the hire date in the format like ex:feb 22,1991. Can anyone provide me the solution for this kind of prob...
@user-uh2cs7uy7r
@user-uh2cs7uy7r Жыл бұрын
You need to check the date formatting function in the RDBMS you are using. In MySQL, there is date_format() function. So, you can use the formatted date in the WHERE clause, write something like : SELECT DATE_FORMAT("2017-06-15", "%b %d,%Y"); SELECT * FROM hr.employees WHERE DATE_FORMAT(hire_date, "%b %d,%Y")='Jun 17,1987';
@pavangsk8404
@pavangsk8404 Жыл бұрын
sir can you make videos on sas for data analytics
@ankitbansal6
@ankitbansal6 Жыл бұрын
I have never worked on SAS brother
@pavangsk8404
@pavangsk8404 Жыл бұрын
@@ankitbansal6 ok sir ... Your videos on SQL are amazing...thankyou for responding
@Vicky-ne9mt
@Vicky-ne9mt Жыл бұрын
hii can anyone suggest me a good website to parctice sql(like interview questions )
@ankitbansal6
@ankitbansal6 Жыл бұрын
Using loc method
@Vicky-ne9mt
@Vicky-ne9mt Жыл бұрын
@@ankitbansal6 what?
@apna9656
@apna9656 Жыл бұрын
Hi Ankit sir In the interview they asked me one question they provided me below table Name. month. Revenue (col name) Adi. Jab. 1000 Adi. Feb. 2000 Jack. Mar. 3000 They want an answer in below format Name. Jab_rev. Feb_rev. Mar_rev How can we do this? Please let us know
@ankitbansal6
@ankitbansal6 Жыл бұрын
kzbin.info/www/bejne/hWfQdZeLfturb80
@theraizadatalks14
@theraizadatalks14 Жыл бұрын
/* CREATE TABLE revenue_data ( Name VARCHAR(50), Month VARCHAR(50), Revenue INT ); INSERT INTO revenue_data (Name, Month, Revenue) VALUES ('Adi', 'Jan', 1000), ('Adi', 'Feb', 2000), ('Jack', 'Mar', 3000); */ -------------------------------------------------- Select * from revenue_data -------------------------------------------------- --1. Using Case When and Groupby Select Name, ISNULL(SUM(Case when month='Jan' then revenue else null end),0) as [Jan_rev], ISNULL(SUM(Case when month='Feb' then revenue else null end),0) as [Feb_rev], ISNULL(SUM(Case when month='Mar' then revenue else null end),0) as [Mar_rev] from revenue_data group by Name -------------------------------------------------- -- 2. Using Pivot Function Select Name,isnull(Jan,0) as [Jan_rev] ,isnull(Feb,0) as [Feb_rev],isnull(Mar,0) as [Mar_rev] from ( Select * from revenue_data ) SourceTbl Pivot ( MAX(revenue) for month in (Jan,Feb,Mar) --([Jan],[Feb],[Mar]) ) PivotTbl --------------------------------------------------
@bodybuildingmotivation5438
@bodybuildingmotivation5438 Жыл бұрын
select NAME ,sum(case when Month ='Jan' then revenue end) as Jan_rev ,sum(case when Month ='Feb' then revenue end) as Feb_rev ,sum(case when Month ='Mar' then revenue end) as Mar_rev from revenue_data group by name
@NikhilKumar-ik9fw
@NikhilKumar-ik9fw Жыл бұрын
Bro I wasn't able to answer this question in Myntra interview and haven't found any helpful Relevant solution, please so help me given three columns "Name of the person won", "Country", "Majority" Assume this whole data set is unique and consists thousands of rows. Give me the data for 100th person from every country while ordering majority in descending order Please give SQL logic Without using rank( window function)
@arjundev4908
@arjundev4908 11 ай бұрын
WITH CTE AS(SELECT *, ROW_NUMBER()OVER(PARTITION BY COUNTRY ORDER BY MAJORITY DESC) AS ID FROM MYNTRA) SELECT NAME FROM CTE WHERE ID%100 = 0; I hope this should help you.
@NikhilKumar-ik9fw
@NikhilKumar-ik9fw Жыл бұрын
Bro I wasn't able to answer this question in Myntra interview and haven't found any helpful Relevant solution, please so help me given three columns "Name of the person won", "Country", "Majority" Assume this whole data set is unique and consists thousands of rows. Give me the data for 100th person from every country while ordering majority in descending order Please give SQL logic Without using rank( window function Please do a video on this or please provide reference video link if done. I hope you'll make a video
@theraizadatalks14
@theraizadatalks14 Жыл бұрын
Hi Can you please clarify the question, what do you mean by Majority ( Try to give a example of small dataset ) ?
@NikhilKumar-ik9fw
@NikhilKumar-ik9fw Жыл бұрын
@@theraizadatalks14 Its the majority of votes won in elections.
All About SQL Aggregations | SQL Advance | Zero to Hero
17:43
Ankit Bansal
Рет қаралды 49 М.
THEY WANTED TO TAKE ALL HIS GOODIES 🍫🥤🍟😂
00:17
OKUNJATA
Рет қаралды 21 МЛН
Did you believe it was real? #tiktok
00:25
Анастасия Тарасова
Рет қаралды 52 МЛН
When You Get Ran Over By A Car...
00:15
Jojo Sim
Рет қаралды 22 МЛН
SQL Interview questions | Data Analyst | Part - 1
11:56
The ML Mine
Рет қаралды 2,2 М.
Top 10+ Data Engineer Interview Questions and Answers
13:18
Jay Feng
Рет қаралды 72 М.
SQL Tutorial - How to use NTILE in SQL Server
15:28
BeardedDev
Рет қаралды 4,8 М.
ОБСЛУЖИЛИ САМЫЙ ГРЯЗНЫЙ ПК
1:00
VA-PC
Рет қаралды 1,7 МЛН
⚡️Супер БЫСТРАЯ Зарядка | Проверка
1:00
1$ vs 500$ ВИРТУАЛЬНАЯ РЕАЛЬНОСТЬ !
23:20
GoldenBurst
Рет қаралды 1,6 МЛН
Собери ПК и Получи 10,000₽
1:00
build monsters
Рет қаралды 2,3 МЛН