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

КОМЕНТАРІ • 22

  • @ankitsrivastava6641
    @ankitsrivastava6641 7 днів тому

    Thank you for the video. Keep taking on new question.

    • @TheMLMine
      @TheMLMine  7 днів тому

      Thanks ankit. Glad it was helpful

  • @anandpathare6421
    @anandpathare6421 9 днів тому

    very good bro , nice and keep it go on

  • @sarashtirathi7587
    @sarashtirathi7587 Місяць тому

    Perfectly 👌✅✅

  • @kirillnaumenko5806
    @kirillnaumenko5806 16 днів тому

    Amazing explanation and delivery! Thank you for your work

    • @TheMLMine
      @TheMLMine  14 днів тому

      Thanks. Glad it was helpful

  • @sweetsubha514
    @sweetsubha514 Місяць тому

    Well explained 👌👌.. Helpful

  • @Pragya3421
    @Pragya3421 Місяць тому +1

    Keep making such sql interview question videos. Pls

    • @TheMLMine
      @TheMLMine  Місяць тому

      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 :)

  • @raviyadav-dt1tb
    @raviyadav-dt1tb Місяць тому +1

    its very helpful brother, but one more suggestion please also include more scenario in same case.

    • @TheMLMine
      @TheMLMine  Місяць тому

      Thanks for the feedback. Point noted

  • @shubhamsoni174
    @shubhamsoni174 15 днів тому

    Please try to bring more such videos 🙏

  • @ankitsinha5088
    @ankitsinha5088 13 днів тому +1

    We can use dense rank as well or rank makes more sense. Can somebody explain?

    • @TheMLMine
      @TheMLMine  13 днів тому

      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.

  • @nishantgautam1581
    @nishantgautam1581 17 днів тому +1

    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 ?

    • @TheMLMine
      @TheMLMine  14 днів тому

      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

  • @Mathew9010
    @Mathew9010 Місяць тому

    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 😊.

    • @TheMLMine
      @TheMLMine  Місяць тому

      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.

    • @TheMLMine
      @TheMLMine  Місяць тому

      And if you like, you can post your interview questions here and I will try to make a separate video on those. Thanks