SQL Interview Question | Capgemini | Data Engineer

Поділитися
Вставка
  • Опубліковано 10 січ 2025

КОМЕНТАРІ • 23

  • @shankarshiva5587
    @shankarshiva5587 28 днів тому +2

    informative video:
    optimal way:
    Select M. id as mgrid, M.name as mgrname,COUNT(*) as No_Of_Employees
    From Employees E inner join employees M
    on E.managerid=M.id
    Group by M.id, M.name
    Having count(*)>4

  • @anuragshrivastava7855
    @anuragshrivastava7855 8 днів тому

    with cte as (select *, rank() over(partition by managerid order by id) as rnk from Employee)
    select distinct managerid from cte where rnk>4 and managerid is not null

    • @codinglake
      @codinglake  8 днів тому

      nice one

    • @rajakumarkeelu9449
      @rajakumarkeelu9449 2 дні тому

      @@codinglake well done, I am still thinking the usage of DISTINCT here. See if I want to query this, rest is same
      WITH CTE AS (
      SELECT *, RANK() OVER (PARTITION BY ManagerID ORDER BY id) AS R_NK
      FROM Employee
      )
      SELECT ManagerID
      FROM CTE
      WHERE R_NK >4
      AND ManagerID IS NOT NULL;
      so just to understand is there any specific reason for using DISTINCT as I am eager to learn that if that is something I never seen before

  • @shanupandey5932
    @shanupandey5932 2 дні тому

    select e1.name,count(e2.managerId) as cnt from employee e1,employee e2
    on e1.id=e2.managerId
    group by e1.name
    having count(e2.managerId) >4

  • @sovon9
    @sovon9 26 днів тому +2

    select name from employees where id in (select managerid from employees group by managerid having count(managerid)>4);

  • @KRANTHIKUMARMARADA
    @KRANTHIKUMARMARADA 4 дні тому

    select count(e.managerid),m.name from employes e join employes m
    on e.managerid=m.id group by m.name having count(e.managerid)>4

  • @Bharatkumar-gh2um
    @Bharatkumar-gh2um 28 днів тому

    You can write without join having(emp)>2 by use grouping

    • @codinglake
      @codinglake  28 днів тому

      You can write many ways, but in this video i have to show step by step process

  • @rajakumarkeelu9449
    @rajakumarkeelu9449 2 дні тому

    SELECT Managerid, staff FROM( SELECT ManagerID, COUNT(name) AS staff FROM Employee GROUP BY ManagerID) AS Subquery WHERE staff >4;

  • @gublu123
    @gublu123 19 годин тому

    Can anybody explain why are we even using partition by??

    • @codinglake
      @codinglake  19 годин тому

      watch this.
      ua-cam.com/video/OkupQBY8yXw/v-deo.html

  • @rajakumarkeelu9449
    @rajakumarkeelu9449 2 дні тому

    SET @Query = CONCAT('SELECT Manager_id, COUNT(name) FROM Employee GROUP BY Manager_ID
    HAVING COUNT(name) >', @Value);
    SET @Value =4;
    PREPARE stmt FROM @Query;
    EXECUTE stmt;
    DEALLOCATE PREPARE stmt;

  • @vivekshirsat9249
    @vivekshirsat9249 28 днів тому +1

    my solution is below
    select
    e2.name as manager_name,
    COUNT(e1.managerId) as no_of_employees
    from Employee as e1
    join Employee as e2
    on e1.managerId = e2.id
    group by e2.name
    having COUNT(e1.managerId) > 4

  • @rajakumarkeelu9449
    @rajakumarkeelu9449 2 дні тому

    WITH Manager4 AS (
    SELECT ManagerID, COUNT(name) AS staff FROM Employee GROUP BY ManagerID
    )
    SELECT ManagerID, staff, RANK() OVER(ORDER BY staff_count DESC) AS Finding_Manager4
    FROM Manager4
    WHERE staff > 4;

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

    Concept clear.

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

    Nice explain

  • @arjunarjun-f3u6j
    @arjunarjun-f3u6j 28 днів тому

    sir its hard

  • @rajakumarkeelu9449
    @rajakumarkeelu9449 2 дні тому

    SELECT e.managerid FROM employee e
    JOIN (SELECT managerid, COUNT(*) AS Employee_Count
    FROM employee
    GROUP BY managerid
    HAVING COUNT(*) > 4) AS Subquery
    ON e.managerid = Subquery.managerid
    GROUP BY e.managerid;