【发布时间】:2014-06-07 21:01:48
【问题描述】:
首先我创建了两个表:
CREATE TABLE min_data(
id integer primary key,
ic char(5) not null,
dt datetime not null,
cou float,
max float not null,
avg float not null,
min float not null);
CREATE TABLE min_data(
id integer primary key,
ic char(5) not null,
dt datetime not null,
cou float,
max float not null,
avg float not null,
min float not null);
CREATE UNIQUE INDEX in_ic_dt on hour_data(ic, dt);
然后我创建了一个触发器,如下所示。
create trigger ins after insert on min_data
begin
replace into hour_data(ic, dt, cou, max, avg, min)
select ic, strftime('%Y-%m-%d %H:00:00', dt), AVG(cou) * 6, MAX(max), AVG(avg), MIN(min) from min_data where strftime('%Y-%m-%d %H:00:00', new.dt) <= dt and dt < strftime('%Y-%m-%d %H:00:00', new.dt, '+1 hour') and ic = new.ic;
end;
这就是问题所在。在我向 min_data 中插入一些记录后,触发器会向 hour_data 中插入一些记录,但是 hour_data 中记录的 id 不是以 1 开头,并且是离散的。我该如何解决这个问题?
【问题讨论】:
标签: sql replace sqlite triggers