SQL INTERVIEW QUESTION | Categorize Salespersons by Sales Amount in SQL

  Рет қаралды 1,536

Data Sculptor

Data Sculptor

Күн бұрын

DML Script: datasculptor.b...
Feedback: forms.gle/NQuC...
Playlists:
SQL Interview Questions: • SQL Interview questions
Recursive CTE: • Recursive CTE
Power BI: • Power BI and DAX
Data Modeling: • Data Modelling
Generative AIs: • Generative AIs
Excel: • Excel
Follow me
Linkedin: / data-sculptor-93a00b2a8
Instagram: / datasculptor2895

Пікірлер: 10
@vijaygupta7059
@vijaygupta7059 Ай бұрын
Using window function in MSSQL DB: with cte as ( Select * ,avg(amount)over(partition by salesperson) as avg_amount ,min(amount)over(partition by salesperson) as min_amount ,max(amount)over(partition by salesperson) as max_amount from sales ) Select salesperson, amount , case when amount=min_amount then 'Lowest' when amount=max_amount then 'Highest' when amountavg_amount then 'Above Average' end as Catogery from cte
@datasculptor2895
@datasculptor2895 Ай бұрын
Nice 👍
@sabesanj5509
@sabesanj5509 Ай бұрын
Awesome brother.
@kujiama7946
@kujiama7946 Ай бұрын
im new learing SQL im gonna go back to this question right here soon!
@datasculptor2895
@datasculptor2895 Ай бұрын
Good luck
@kujiama7946
@kujiama7946 Ай бұрын
@@datasculptor2895 Hello Brother im back # usage of windows function so no need to think about anything max avg and lowest SELECT salesperson, amount, CASE WHEN amount = high THEN "Highest" WHEN amount > avg AND amount < high THEN "Above Average" WHEN amount = avg THEN "Average" WHEN amount < avg AND amount > low THEN "Below Average" WHEN amount = low THEN "Lowest" END as Category FROM ( SELECT *, avg(amount) over(partition by salesperson) as avg, -- average max(amount) over(partition by salesperson) as high, -- highest min(amount) over(partition by salesperson) as low -- highest FROM sales ) AS Sales
@monasanthosh9208
@monasanthosh9208 Ай бұрын
Select *,Case When Amount=Min(Amount) over (Partition by Sales_person Order by Amount asc) Then "Lowest" When Amount=Max(Amount) over (Partition by Sales_person Order by Amount Desc) Then "Highest" When Amount=Avg(Amount) over (Partition by Sales_person Range between unbounded preceding and unbounded following) Then "Average" When Amount>Avg(Amount) over (Partition by Sales_person Range between unbounded preceding and unbounded following) Then "Above Average" When Amount
@datasculptor2895
@datasculptor2895 Ай бұрын
Nice. Please subscribe to my channel
@sabesanj5509
@sabesanj5509 Ай бұрын
Brother please mention the question in description section or in blog site.
@datasculptor2895
@datasculptor2895 Ай бұрын
Ok.
SQL Interview Problem asked during Amazon Interview
15:15
techTFQ
Рет қаралды 24 М.
When you discover a family secret
00:59
im_siowei
Рет қаралды 32 МЛН
Blue Food VS Red Food Emoji Mukbang
00:33
MOOMOO STUDIO [무무 스튜디오]
Рет қаралды 32 МЛН
Zombie Boy Saved My Life 💚
00:29
Alan Chikin Chow
Рет қаралды 33 МЛН
SQL INTERVIEW QUESTION | Retrieve DISTINCT Orders
8:38
Data Sculptor
Рет қаралды 1,4 М.
What does a Data Analyst actually do? (in 2024) Q&A
14:27
Tim Joo
Рет қаралды 53 М.
Practice SQL Interview Query | Big 4 Interview Question
14:47
Day in the Life of a Data Analyst (Work From Home) | *Realistic*
9:05
Coding with Dee
Рет қаралды 45 М.