The Questions Are Broken Into Q1 4 Marks Q2 3 Marks Q3 And Q4
The Questions Are Broken Into Q1 4 Marks Q2 3 Marks Q3 And Q4
Write and run SQL statements for creating the Occurrence_Exercise table. Include constraint values for the Condition Column: Heavy, Medium, Light. Write an SQL statement that will insert the data into Occurrence_Exercise table only. Definition of rep stands for repetition. Each exercise attempt has the rep number as indicated in the occurrence table. Occurrence Table OccurrenceID Occ_Date Occ_Place Occ_Start_Time Occ_Finish_Time 1 14/03/18 University_Gym 16:00::30:/03/18 University_Gym 16:30::00:/03/18 University_Gym 16:10::20:/03/18 Home 07:00::00:/03/18 University_Gym 17:00::00:00 Occurrence_Exercise Table OccExID ExerciseNo OccurrenceID Rep Attempt1 Attempt2 Attempt3
Condition A Light A Medium A Heavy A Medium A Heavy A Medium A Medium A Heavy Exercise Table ExerciseNo ExerciseDescription ExerciseType 001A Situps Abs 002A Bench Press Chest 003A Dead Lifts Back 004A Leg Press Legs 005A Seated Shoulder Press Shoulders 006A Squats Legs 007A Lat pull downs Lats Write the following SQL queries: Find the exercise with the maximum total weight lifted and show the exercise name and maximum weight. List in ascending order the exercises that the user was not able to complete 3 attempts in, or exercises that the user has not attempted. Ensure that you only show one occurrence per exercise and include captions for each column.
Paper For Above instruction
The provided task involves creating an SQL table named Occurrence_Exercise for recording exercise attempts, with constraints on the Condition
column. The primary focus is on accurately modeling the data, inserting relevant data entries, and performing specific analytical queries regarding exercise performance. The task emphasizes understanding exercise attempts, weight calculations, and identifying exercises based on total weight lifted and attempt completion status.
Creating the Occurrence_Exercise

Occurrence_Exercise
table must include columns such as OccExID (a unique identifier),
ExerciseNo (foreign key referencing exercises), OccurrenceID (linking to occurrences),
Rep (number of repetitions), Attempt1 , Attempt2 , Attempt3 (weights lifted in each attempt), and Condition with constrained values of 'Heavy', 'Medium', 'Light'.
The table creation SQL statement should include constraints for the Condition column using ENUM or CHECK constraints depending on the SQL dialect. Here's a typical

implementation in standard SQL:
CREATE TABLE Occurrence_Exercise (
OccExID INT PRIMARY KEY,
ExerciseNo VARCHAR(10) NOT NULL,
OccurrenceID INT NOT NULL,
Rep INT NOT NULL,
Attempt1 DECIMAL(5,2),
Attempt2 DECIMAL(5,2),
Attempt3 DECIMAL(5,2),
Condition VARCHAR(6) CHECK (Condition IN ('Heavy', 'Medium', 'Light'))
);
This table structure captures each exercise attempt with the relevant details and constraints on the 'Condition' values.
Inserting Data into the Occurrence_Exercise
table
Insertion statements should populate this table with data corresponding to the exercise attempts logged in the session. For example, sample insert statements could look like:
INSERT INTO Occurrence_Exercise (OccExID, ExerciseNo, OccurrenceID, Rep, Attempt1, Attempt2, Attempt3, Condition) VALUES
(1, '001A', 1, 10, 15.0, 15.0, 15.0, 'Light'),
(2, '002A', 1, 8, 40.0, NULL, NULL, 'Medium'), (3, '003A', 2, 5, 50.0, 55.0, 60.0, 'Heavy'), (4, '004A', 3, 12, 60.0, 65.0, NULL, 'Medium'),

(5, '005A', 4, 10, 20.0, 20.0, 20.0, 'Light');
Data should be entered according to actual exercise attempts and conditions, ensuring updating or inclusion of necessary records for accurate analysis.
SQL Queries for Data Analysis
1. Finding the exercise with maximum total weight lifted
This query calculates total weight lifted per exercise by summing across attempts, considering Rep , attempts, and weight per attempt. It then identifies the exercise with the highest total weight lifted.
SELECT e.ExerciseDescription AS Exercise,
MAX(SUM( Rep *
(COALESCE(Attempt1, 0) + COALESCE(Attempt2, 0) + COALESCE(Attempt3, 0))
)) AS Maximum_Weight FROM Exercise e
JOIN Occurrence_Exercise oe ON e.ExerciseNo = oe.ExerciseNo
GROUP BY e.ExerciseDescription
ORDER BY Maximum_Weight DESC
LIMIT 1;
2. Listing exercises not completed in all three attempts or not attempted at all
This query identifies exercises where fewer than three attempts were completed or no attempts at all, providing relevant details. Sorting is in ascending order by exercise type, with duplicates eliminated.
SELECT DISTINCT e.ExerciseDescription AS Exercise, e.ExerciseType AS Exercise_Type FROM Exercise e

LEFT JOIN Occurrence_Exercise oe ON e.ExerciseNo = oe.ExerciseNo
WHERE
oe.Attempt3 IS NULL OR
(oe.Attempt1 IS NULL AND oe.Attempt2 IS NULL AND oe.Attempt3 IS NULL)
ORDER BY e.ExerciseType ASC;
These queries support performance analysis and assessment of workout completion status, enabling insights into exercise effectiveness and user adherence.
Conclusion
The creation of the
Occurrence_Exercise
table with appropriate constraints, coupled with insertions and these analytical queries, facilitates effective tracking and evaluation of exercise sessions. The calculations of total weight lifted provide insights into workout intensity, while identifying incomplete or unattempted exercises helps tailor future training plans. Together, these SQL operations form the basis for comprehensive gym session data management and analysis.
References
Elmasri, R., & Navathe, S. B. (2015).
Fundamentals of Database Systems (7th ed.). Pearson.
International Journal of Computer Science and Mobile Computing , 6(4), 101-107.
Transaction Processing: Concepts and Techniques
. Morgan Kaufmann.
Database Journal

.
Database Systems: A Practical Approach to Design, Implementation, and Management
. Pearson.
Database System Concepts . McGraw-Hill.
Database Design and Relational Theory . O'Reilly Media.
Database Management Systems . McGraw-Hill.
. Van Hardeveld, N. (2018). Enhancing data integrity with SQL constraints.
International Journal of Data Management
.
