【问题标题】:How to force the range of 2 timestamps in a row如何强制连续 2 个时间戳的范围
【发布时间】:2019-12-09 01:59:05
【问题描述】:

我需要捕获两个不同的时间戳,一个用于incoming_patients,另一个用于outcoming_patients。我需要限制 outcoming_patient 时间戳必须晚于传入的时间戳。

create table hold (
incoming_date timestamp,
outcoming_date timestamp CHECK (EXTRACT(HOUR FROM incoming_date) > (EXTRACT(HOUR FROM outcoming_date)),

提前致谢。

【问题讨论】:

  • 是sql server吗?
  • 为什么只检查小时而不检查分钟、秒、日、年和月?如果incoming_date 应该晚于outcoming_date 你应该简单地使用check (outcoming_date > incoming_date)?
  • 嗨。感谢您的回复。我在mysql上,我会发布解决方案。

标签: mysql sql timestamp


【解决方案1】:

作为@T.S,我没有理解时间戳的含义。

我对 SO 进行了大量研究,试图了解如何比较两个时间戳,但这并不是我真正需要的。这是第一个麻烦,第二个是我升级了自己的怀疑。所以更容易了。

create table hold (    
    incoming_date DATETIME,
    outcoming_date DATETIME check (outcoming_date>incoming_date),
);

【讨论】:

  • 您至少需要 MySQL 8.0。 16 否则检查约束将被忽略
猜你喜欢
  • 2014-12-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-07
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多