Having viewed several matrials both here on Stack Overflow and other external sources, I am attempting to write a piece of code to generate a view that performs a calculation utilising data from other tables, The aim of the code is:
- To Acquire username from the UserDetails table
- Acquire weight in pounds from the UserDetails Table
- Acquire distance_in_miles from the Cardiovascular Records table
- Use the weight and distance in a calculation as shown below which is output as the caloriesBurned column.
My attempt can be seen below:
CREATE VIEW CardioCaloriesBurned (username, weight, distance, caloriesBurned) AS
SELECT UserDetails.username, UserDetails.weight_in_pounds,
CardiovascularRecords.distance_in_miles ,
((0.75 X weight_in_pounds) X distance_in_miles)
FROM UserDetails, CardiovascularRecords
If anyone could help in correcting this issue It would be greatly appreciated.
Edit: I am getting a syntax error in SQLite Manager relating to a "(" however Im not seeing any issues myself.
Edit: Code for the Cardiovascular Table and UserDetails table below:
CREATE TABLE "CardiovascularRecords" ("record_ID" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE CHECK (record_ID>0) , "distance_in_miles" REAL NOT NULL CHECK (distance_in_miles>0) , "username" TEXT NOT NULL , "date" DATETIME DEFAULT CURRENT_DATE, "notes" TEXT(50), "start_time" TEXT, "end_time" TEXT, FOREIGN KEY(distance_in_miles) REFERENCES DistanceinMiles(distance_in_miles) ON DELETE CASCADE ON UPDATE CASCADE,FOREIGN KEY(username) REFERENCES UserDetails(username) ON DELETE CASCADE ON UPDATE CASCADE)
CREATE TABLE "UserDetails" ("username" TEXT PRIMARY KEY NOT NULL UNIQUE CHECK (length(username)>0), "password" TEXT NOT NULL CHECK (length(password)>3), "email_address" TEXT NOT NULL UNIQUE CHECK (length(email_address)>3) , "weight_in_pounds" REAL NOT NULL CHECK(weight_in_pounds>0) CHECK (length(weight_in_pounds)>0), "height_in_inches" REAL NOT NULL CHECK(height_in_inches>0) CHECK (length(height_in_inches)>0), "age" INTEGER CHECK(age>0), WITHOUT ROWID)
Thanks
JHB92