【发布时间】:2017-03-15 18:16:04
【问题描述】:
我想将行插入到具有日期和信息列的表中。如果已经有一行具有相同的信息值且日期与今天相差 >= 1 天,则不应发生插入。
假设当前日期:2017-01-03
id, info, date
1, a, 2017-01-01
2, b, 2017-01-02
要插入的新行:
info
c
a
b
预期操作:
c: gets inserted because no other row has the same info value
a: gets inserted because existing a has a date more than 1 day in the past
b: no insert because the time difference is not big enough
预期结果:
id, info, date
1, a, 2017-01-01
2, b, 2017-01-02
3, c, 2017-03-03
4, a, 2017-03-03
【问题讨论】:
-
我认为您需要为此创建一个触发器。