SQL User Stories
SQL User Stories
1.Employee Table
Create a table to store employee details with the following structure and
insert data:
- `employee_id`: Serial, Primary Key
- `first_name`: VARCHAR(50), Not Null
- `last_name`: VARCHAR(50), Not Null
- `email`: VARCHAR(100), Unique, Not Null
- `hire_date`: DATE, Not Null
- `salary`: DECIMAL(10, 2), Not Null
- `department_id`: INT, Foreign Key (References `departments`)
- `manager_id`: INT, Foreign Key (References `employees`)
2.Department Table
Create a table to store department information and insert data:
- `department_id`: Serial, Primary Key
- `department_name`: VARCHAR(100), Not Null
3.Project Table
Create a table to store project details and insert data:
- `project_id`: Serial, Primary Key
- `project_name`: VARCHAR(100), Not Null
- `start_date`: DATE, Not Null
- `end_date`: DATE (nullable)
4.Employee_Project Table
Create a table that links employees to projects and insert data:
- `employee_id`: INT, Foreign Key (References `employees`)
- `project_id`: INT, Foreign Key (References `projects`)
- `role`: VARCHAR(50), Primary Key (Combination of `employee_id` and
`project_id`)
5.Payroll Table
Create a table to store employee payroll information and insert data:
- `payroll_id`: Serial, Primary Key
- `employee_id`: INT, Foreign Key (References `employees`)
- `base_salary`: DECIMAL(10, 2)
- `bonus`: DECIMAL(10, 2)
- `total_salary`: DECIMAL(10, 2)
- `payment_date`: DATE
6. Attendance Table
Create a table to track employee attendance and insert data:
- `employee_id`: INT, Foreign Key (References `employees`)
- `check_in`: TIMESTAMP, Primary Key (Combination of `employee_id` and
`check_in`)
- `check_out`: TIMESTAMP
start_date: DATE
end_date: DATE
Note:- While inserting data into the table go through all the User stories and
enter data based on them, this data will be reused in all the user stories.
Acceptance Criteria:
Create table and Insert data into those tables.
Add Screen shots of tables in tasks.
User story 2:
As a developer, I need to write the queries for the questions using joins.
4. Get Total Salary for Each Employee - Write a query to fetch the
first name, last name, and total salary (base salary + bonus) for all
employees from the `payroll` table.
Acceptance Criteria:
Write the queries for above question.
Add Screen shots of Queries and Results in tasks.
User Story 3:
As a developer, I need to write queries for the questions below using CTE.
Hint: First, use the CTE to calculate the average salary, and then use that
CTE in the main query to filter employees.
Hint: Use a CTE to first group by department in the `employees` table and
then count the employees.
Hint: Use a CTE to filter training programs by `start_date` and then join with
`employee_training_enrollment` and `employees`.
Hint: Use a CTE to count the number of projects each employee is assigned
to from the `employee_project` table, and then filter for those with more
than 1 project in the main query.
Acceptance Criteria:
Write the queries for above question.
Add Screen shots of Queries and Results in tasks.
User Story 4
Acceptance Criteria:
Write the queries for above question.
Add Screen shots of Queries and Results in tasks.
User Story 5
Acceptance Criteria:
Write the queries for above question.
Add Screen shots of Queries and Results in tasks.