表格中的3个字段:START_DATE,END_DATE,DIFF。这三个都是DATETIME字段。我想要一个触发器(AFTER UPDATE)来计算DIFF字段中START_DATE和END_DATE值之间的时差。我希望结果如下:01天 - 12小时 - 15分钟。我怎样才能做到这一点?我想知道它是如何完成的,即显示小时差异的方式,以便DIFF显示类似于27:15:00。
这似乎有效:
CREATE TRIGGER [DIFF]
AFTER UPDATE OF [end_date]
ON [Table1]
BEGIN
UPDATE Table1 SET DIFF =
cast(
(
strftime('%s',Table1.end_date)-strftime('%s',Table1.start_date)
) AS INT
) / 60/60 ;
END
答案 0 :(得分:0)
据我所知,这可行:
CREATE TRIGGER [TIME_DIFFERENCE]
AFTER UPDATE OF [end_date]
ON [Table1]
BEGIN
UPDATE Table1 SET DIFF =
cast(
(
strftime('%s',Table1.end_date)-strftime('%s',Table1.start_date)
) AS INT
) / 60/60 ;
END