我正在尝试将记录为TEXT的两个时间值转换为数值,以便在计算中用于计算差异,这将在视图中实现。
我目前的尝试如下。
CREATE VIEW TimeTakenSwimming AS
SELECT UserDetails.username AS username,
SwimmingRecords.distance_in_miles AS distance,
SwimmingRecords.start_time AS starttime,
SwimmingRecords.end_time AS endtime,
sum((strftime('%s', end_time) - strftime('%s', start_time)) AS timedifference,
FROM UserDetails INNER JOIN SwimmingRecords ON UserDetails.username = SwimmingRecords.username;
现在,我正在接受与" AS"相关的错误。句法。我已经通过并纠正了任何缺失的空格,从SUM计算中添加了缺少的括号等,但是在实现时我仍然收到所述的语法错误。
下面是与我的架构相关的代码,允许其他人尝试复制该问题,我已经使用SQLite管理器Firefox插件来实现此系统。
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
)
CREATE TABLE "SwimmingRecords" (
"record_ID" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL UNIQUE CHECK (record_ID>0) ,
"distance_in_miles" REAL NOT NULL CHECK (distance_in_miles>0) ,
"num_of_lengths" REAL NOT NULL CHECK(num_of_lengths>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(num_of_lengths) REFERENCES NumberOfLengths(num_of_lengths) ON DELETE CASCADE ON UPDATE CASCADE,
FOREIGN KEY(username) REFERENCES UserDetails(username)ON DELETE CASCADE ON UPDATE CASCADE
)
我提前感谢您的任何帮助。
答案 0 :(得分:0)
sum
后括号太多,FROM
之前有错误的逗号:
CREATE VIEW ...
SELECT ...,
sum(strftime('%s', end_time) - strftime('%s', start_time)) AS timedifference
FROM ...;