Sort by

recency

|

3294 Discussions

|

  • + 0 comments

    Guys this is the simplest query by using last table which is having entire data except founders. Hope you find it useful.

    SELECT E.company_code, C.founder, E.total_LM, E.total_SM, E.total_MC, E.total_EC FROM ( SELECT company_code, COUNT(DISTINCT lead_manager_code) AS total_LM, COUNT(DISTINCT senior_manager_code) AS total_SM, COUNT(DISTINCT manager_code) AS total_MC, COUNT(DISTINCT employee_code) AS total_EC FROM Employee GROUP BY company_code ) AS E JOIN Company AS C ON E.company_code = C.company_code ORDER BY E.company_code;

  • + 0 comments

    select c.company_code, c.founder, count(distinct(e.lead_manager_code)), count(distinct(e.senior_manager_code)), count(distinct(e.manager_code)), count(distinct(e.employee_code)) from Company c left join Employee e on c.company_code=e.company_code GROUP by c.company_code , c.founder order by c.founder this query is running but answer is wrong why that so

  • + 0 comments
    SELECT
        E.company_code,
        C.founder,
        E.c_lead_manager_code,
        E.c_senior_manager_code,
        E.c_manager_code,
        E.c_employee_code
    FROM (
        SELECT
            company_code,
            COUNT(DISTINCT employee_code) AS c_employee_code,
            COUNT(DISTINCT manager_code) AS c_manager_code,
            COUNT(DISTINCT senior_manager_code) AS c_senior_manager_code,
            COUNT(DISTINCT lead_manager_code) AS c_lead_manager_code
        FROM Employee
        GROUP BY company_code
    ) E JOIN Company C ON E.company_code = C.company_code
    ORDER BY E.company_code ASC;
    
  • + 0 comments

    I know there are simpler ways to solve this problem, but I want to figure it out using a non-correlated subquery, because I've just studied it.

    My solution in MySQL:

    SELECT
        c.company_code,
        c.founder,
        (SELECT COUNT(DISTINCT lead_manager_code) FROM lead_manager l WHERE l.company_code = c.company_code) AS total_lead_managers,
        (SELECT COUNT(DISTINCT senior_manager_code) FROM senior_manager s WHERE s.company_code = c.company_code) AS total_senior_managers,
        (SELECT COUNT(DISTINCT manager_code) FROM manager m WHERE m.company_code = c.company_code) AS total_managers,
        (SELECT COUNT(DISTINCT employee_code) FROM employee e WHERE e.company_code = c.company_code) AS total_employee
    FROM company c 
    ORDER BY c.company_code ASC 
    
  • + 0 comments

    there is no need to use all the tables. All the components are present in the employee table except founders names. so we can just use the company table and the employee table here's my code: SELECT c.company_code, c.founder, COUNT(DISTINCT e.lead_manager_code ) AS total_lm, COUNT(DISTINCT e.senior_manager_code ) AS total_sm, COUNT(DISTINCT e.manager_code ) AS total_m, COUNT(DISTINCT e.employee_code ) AS total_e FROM company c LEFT JOIN employee e ON c.company_code=e.company_code GROUP BY c.company_code, c.founder ORDER BY c.company_code;