question

Pratyusha avatar image
Pratyusha asked

Inserting records from multiple tables

So basically i have 3 tables: Project ( Project_id(PK), Project_Name, Client_Name) Employee(Employee_id (PK),Employee_Name, Project_id(FK referencing Project Table) Leave(Leave_id(PK), Leave_date, Employee_id (FK referencing Employee Table) I have to create a new table **Employee_Leave_Count( Employee_name, Project_name, Leave_count)** by inserting values from the above 3 tables. Please help me
tables
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
AlexKlap avatar image
AlexKlap answered
try this. ;WITH CTES AS ( SELECT EMP.Employee_name, PR.Project_name,L.Leave_id FROM Project PR INNER JOIN Employee EMP ON PR.Project_id = EMP.Project_id INNER JOIN Leave L ON L.Employee_id = EMP.Employee_id ) SELECT Employee_Name,Project_Name , COUNT (Leave_id) LEAVE_COUNT INTO #Employee_Leave_Count FROM CTES GROUP BY Employee_Name,Project_Name
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.