The Number of Employees Which Report to Each Employee | Leetcode 1731 | Crack SQL Interviews

Поделиться
HTML-код
  • Опубликовано: 3 дек 2024

Комментарии • 13

  • @learnwithchirag
    @learnwithchirag  8 месяцев назад

    Hey there! 👋 For more interesting content, tutorials, and updates, Feel free to connect with me on
    Instagram Handles :-
    @createwithchirag - instagram.com/createwithchirag/
    @learn.with.chirag - instagram.com/learn.with.chirag/
    LinkedIn: www.linkedin.com/in/chirag-sehgal-9200111b8/
    Let's stay connected and keep the creativity flowing! 💡

  • @apoorvpradhan5125
    @apoorvpradhan5125 4 месяца назад

    Thank you bhaiya.

  • @mohammedmaqdoom4410
    @mohammedmaqdoom4410 6 месяцев назад

    thanks chirag this side

  • @BlendTubeMix
    @BlendTubeMix Месяц назад +1

    # Write your MySQL query statement below
    SELECT E1.employee_id,E1.name,COUNT(E2.reports_to) AS reports_count,ROUND(AVG(E2.age)) AS average_age
    FROM Employees E1, Employees E2
    WHERE E1.employee_id = E2.reports_to
    GROUP BY E1.employee_id, E1.name
    ORDER BY E1.employee_id

  • @prathamsharma4416
    @prathamsharma4416 8 месяцев назад

    nice one bro

    • @learnwithchirag
      @learnwithchirag  8 месяцев назад +1

      thanks a lot ! glad it was helpful ❤️

  • @divinepandit1815
    @divinepandit1815 11 месяцев назад +1

    Bhaiya ji kaisa pata hoga ki kon sa attribute kon se table se lena hai

    • @learnwithchirag
      @learnwithchirag  11 месяцев назад +2

      It is usually based on our joining condition. You can also reverse it ( i.e take E1 as E2 and E2 as E1 ) it will still be the same.
      Try to dry run the code to get more insight. Write SELECT * and run the query once.

    • @prathamsharma4416
      @prathamsharma4416 8 месяцев назад +1

      @@learnwithchirag yeah , that helped me, its like 2 table joined with all attributes

  • @riteshchaudhary8755
    @riteshchaudhary8755 6 месяцев назад

    Hello brother,i want to ask one thing that why e2.age and e2.employee_id are used and when i use e1.employee_id or e1.age it is showing wrong answer.Can you explain why?

    • @vineetkarmakar2305
      @vineetkarmakar2305 4 месяца назад +1

      when you use e1.employee_id and e1.age it takes the values from the first table
      and when you use e2.employee_id and e2.age it takes the value from the second table jo humne join kia hai first table ke uppar
      e1.age use karega to manager ki age ka average ajaega par humne unka age ka avg chahiye jo manager ko report kar rahe hai
      and humne count bhi un bando ko karna hai ki kitne bande manager ko report kar rahein hain not ki kitne manager hai jisko log report kar rahein hai