SQL INTERVIEW QUESTION | Categorize Customers Based on Conditions

  Рет қаралды 989

Data Sculptor

Data Sculptor

Күн бұрын

Пікірлер: 12
@mayamajhi7842
@mayamajhi7842 Ай бұрын
Explained well
@datasculptor2895
@datasculptor2895 Ай бұрын
Thank you
@user-gq6cg3ls7f
@user-gq6cg3ls7f Ай бұрын
Thank you for the good question My approach: with cte as( SELECT *, MONTH(DateOfPurchase) months, ROW_NUMBER() over (partition by CustomerID order by DateOfPurchase) RN, DATEADD(MONTH, -1 * ROW_NUMBER() over (partition by CustomerID order by DateOfPurchase), DateOfPurchase) bucket, count(DateOfPurchase) over (partition by CustomerID) cnt, SUM(revenue) over (partition by CustomerID) total_revenue, SUM(case when ModeOfPurchase = 'Online' then 1 else 0 end) over (partition by CustomerID) online_customer FROM CustomerPurchases ) select distinct customerID, case when months - RN =2 and cnt >= 6 then 'Regular Customer' when total_revenue>=5000 then 'Top Customer' when cnt = online_customer then 'Online Customer' Else 'Average Customer' END Type from cte
@datasculptor2895
@datasculptor2895 Ай бұрын
Nice
@akhilsingh5251
@akhilsingh5251 Ай бұрын
Hi sir, Kindly put create and insert statements in comment section so , that we can save our time and do more questions. Thanks
@datasculptor2895
@datasculptor2895 Ай бұрын
It’s there in description
@ajittiwari4504
@ajittiwari4504 Ай бұрын
with cte as ( SELECT customerid, sum(Revenue) over(partition by customerid) as total_spent, subdate(DateOfPurchase, interval row_number() over(partition by customerid order by DateOfPurchase) month) as cnt, case when ModeOfPurchase = 'Online' then 1 else 0 end as flag FROM CustomerPurchases) select customerid, case when count(cnt)>=5 then 'Regular customer' when total_spent>=5000 then 'Top customer' when min(flag) =1 then 'Online customer' else 'Average Customer' end as Category from cte group by customerid, total_spent;
ACCENTURE SQL INTERVIEW QUESTION | Change the ProductIDs
9:47
Data Sculptor
Рет қаралды 4,5 М.
FLIPKART DATA ANALYST SQL INTERVIEW QUESTION | Activity Time
14:52
🕊️Valera🕊️
00:34
DO$HIK
Рет қаралды 18 МЛН
黑的奸计得逞 #古风
00:24
Black and white double fury
Рет қаралды 29 МЛН
I tricked MrBeast into giving me his channel
00:58
Jesser
Рет қаралды 26 МЛН
А что бы ты сделал? @LimbLossBoss
00:17
История одного вокалиста
Рет қаралды 12 МЛН
The 25 SQL Questions You MUST Know for Data Analyst Interviews
32:47
KSR Datavizon
Рет қаралды 237 М.
Forward Fill Null Values  - 2 WAYS TO SOLVE |  Tricky SQL Questions
11:23
KPMG SQL INTERVIEW QUESTION | JSON input
9:15
Data Sculptor
Рет қаралды 802
Top 10 Data Analyst Interview Questions (with answers)
15:58
TCS Prime Interview Experience | How to Crack TCS Prime
11:45
Ashish Kumar
Рет қаралды 15 М.
SQL INTERVIEW QUESTION | Indian Income Tax Calculations
19:15
Data Sculptor
Рет қаралды 618
Mu Sigma SQL INTERVIEW QUESTION | Consecutive events count
12:26
🕊️Valera🕊️
00:34
DO$HIK
Рет қаралды 18 МЛН