SQL Interview questions | Data Analyst | Part - 2
Вставка
- Опубліковано 1 сер 2024
- This video is the second part of our series on SQL interview questions and answers. This series is specifically designed for people targeting jobs as data analysts, data scientists, data engineers, and business analysts.
In this video, I have explained how to use the RANK() OVER PARTITION() function to find the second highest-selling product in each category.
Use the below the commands to create your own database and table:
CREATE DATABASE THEMLMINE;
USE THEMLMINE;
CREATE TABLE sales (
order_id INT PRIMARY KEY,
product_name varchar(20) NOT NULL,
units_sold INT DEFAULT 0,
unit_price FLOAT
);
CREATE TABLE products (
category varchar(20) NOT NULL,
product varchar(20)
);
INSERT INTO sales VALUES
(122,'Bikaji_namkeen',1500,200),
(112,'Lays',10000,20),
(110,'Amul_kool',2200,25),
(138,'Dairy_milk',2000,149),
(202,'Monaco',9000,50),
(118,'Coke',7000,95),
(104,'Appy_fizz',8000,35),
(189,'KitKat',4500,70),
(238,'Dosa_batter',3000,99),
(199,'Munch',4500,80),
(448,'Maggi',10000,168);
INSERT INTO products VALUES
('Snacks','Bikaji_namkeen'),
('Snacks','Lays'),
('Snacks','Monaco'),
('Drinks','Amul_kool'),
('Drinks','Coke'),
('Drinks','Appy_fizz'),
('Chocolates','KitKat'),
('Chocolates','Munch'),
('Chocolates','Dairy_milk'),
('Instant_food','Dosa_batter'),
('Instant_food','Maggi');
You can download the final script from here: drive.google.com/file/d/1diLH...
Learn SQL from scratch: • SQL Tutorial for begin...
Instagram: / the_ml_mine
Timestamps:
00:00 Introduction
00:05 Interview question
03:20 MySQL workbench
04:53 Writing SQL query
09:48 Using subquery method
11:50 Using CTE method
12:37 Outro
Music credits:
Intro music - Education - upbeat positive (short ver.) by AudioCoffee -- freesound.org/s/724628/
-- License: Attribution NonCommercial 4.0
Thank you for the video. Keep taking on new question.
Thanks ankit. Glad it was helpful
very good bro , nice and keep it go on
Thanks anand
Perfectly 👌✅✅
Amazing explanation and delivery! Thank you for your work
Thanks. Glad it was helpful
Well explained 👌👌.. Helpful
Thanks subha
Keep making such sql interview question videos. Pls
Sure, I already have part - 3 and part - 4 as well in this series. If you have any specific category of question that you want me to cover which is often asked in any interview, then let me know. I will make a separate video on that :)
its very helpful brother, but one more suggestion please also include more scenario in same case.
Thanks for the feedback. Point noted
Please try to bring more such videos 🙏
Sure shubham
We can use dense rank as well or rank makes more sense. Can somebody explain?
Hi ankit, you are right. You can use dense_rank method as well. The only difference is if revenue of two products are same they will get the same rank value when using dense rank function while they will get different rank values when using simple rank function.
bro i understand everything in sql , but when i start solving queries i take lot of time , i take lot of time to understand how shud i type it , any suggestion ?
Hi Nishant, it is normal in the beginning that it will take time to solve queries. That is why we need practice and practice.
My suggestion would be to also understand the order of execution in which the commands are executed. It will help you understand the function of each commands and what happens in the backend (with order). You can refer this link, if it helps: sqlbolt.com/lesson/select_queries_order_of_execution
And please practice questions without jumping at the solution and then understanding it backwards. Try to solve them by yourself first, be it wrong or right. Let me know if you need further help
Brother make a video on TCS SQL interview questions for freshers 😊. I learned SQL in 4 days. But I should prepare interview questions 😅. I have interview on 5th July. And give me tips as I am a fresher 😊.
Hello Mathew, good luck with your interview. However, I am sorry as I will not be able to make the video in this short period. But I have some tips for you -
Tips: You can watch videos on TCS interview recordings conducted by TCS team itself (Link: ua-cam.com/video/yqqnKfms3Pg/v-deo.html). Prepare both theory and practice questions. For theory you can refer to this video: ua-cam.com/video/OLusO6Wdkqw/v-deo.htmlsi=DcaIwO4PmWa0iJHy
Hope you get through the interview.
P.S. Never pretend if you don't know the answer, interviewers are smart enough to catch that. Be confident.
And if you like, you can post your interview questions here and I will try to make a separate video on those. Thanks