Answered step by step
Verified Expert Solution
Link Copied!

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,

10 Meesho Business Analyst
2. Idencify all possible bugs in below Scenario based sql code - Part 2
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 taskcounts AS
SELECT
t.projectid,
t.employeeid,
COUNT (t.task_id) AS task_count,
ROW_NUMBER() OVER (PARTITION BY t.project_id ORDER BY COUNT (t.task_id) DESC) AS rank, LEAD(COUNT (t.task_id),1) OVER (PARTITION BY t.project_id ORDER BY COUNT (t.task_id) ASC) AS Lead_taSkS,
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

How would you collect those additional data?

Answered: 1 week ago