Answered step by step
Verified Expert Solution
Question
1 Approved Answer
1 0 Meesho Business Analyst 2 . Idencify all possible bugs in below Scenario based sql code - Part 2 You have three tables: projects,
Meesho Business Analyst
Idencify all possible bugs in below Scenario based sql code Part
You have three tables: projects, tasks, and employees. Your task is to write an SQL query that:
Calculates the total number of tasks for each project and the average number of tasks per project.
Lists each project's name, the name of the project manager, and the total number of tasks.
For each employee assigned to a project, shows:
Their name and the number of tasks they are responsible for.
Their rank within the project based on the number of tasks most tasks ranks first
The number of tasks of the employee just above and just below them in the ranking.
Even if a project has no tasks, it should still be included in the result with NULL for the average number of tasks.
WITH ounts
SELECT
COUNT ttaskid AS taskcount,
ROWNUMBER OVER PARTITION BY tprojectid ORDER BY COUNT ttaskid DESC AS rank, LEADCOUNT ttaskid OVER PARTITION BY tprojectid ORDER BY COUNT ttaskid ASC AS LeadtaSkS,
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started