SQL 将日期/时间减去一个值

发布于 2024-12-10 09:45:32 字数 821 浏览 0 评论 0原文

我有几列:

|  Start             |   END              |  Duration
2008-06-28 18.03.55 | 2008-10-06 01.33.55 |  End - Start

我的代码如下所示:

SELECT theDelivery,
(char(theDelivery) || ' ' || char(current time)) AS Begin,
(char(theDelivery + 100 DAYS) || ' ' || char(current time + 7 HOURS + 30 MINUTES)) AS End

这是我关于做减法的想法......但它是错误的。我知道你不能减去别名'有什么想法吗? ((char(当前时间 + 7 小时 + 30 分钟) -(char(theDelivery + 100 天)))


所以我发现我的 char 完全错了。我想出了这个,这正是我正在寻找的:

SELECT theDelivery,
TIMESTAMP(theDelivery, current time) AS Begin
,
TIMESTAMP((theDelivery + 100 DAYS), (current time + 7 HOURS + 30 MINUTES)) AS End,
TIMESTAMP((theDelivery + 100 DAYS), (current time + 7 HOURS + 30 MINUTES)) - TIMESTAMP(theDelivery, current time) AS MyDur

I have several columns:

|  Start             |   END              |  Duration
2008-06-28 18.03.55 | 2008-10-06 01.33.55 |  End - Start

My code looks like this:

SELECT theDelivery,
(char(theDelivery) || ' ' || char(current time)) AS Begin,
(char(theDelivery + 100 DAYS) || ' ' || char(current time + 7 HOURS + 30 MINUTES)) AS End

Here is what i thought about doing the subtraction... But its wrong. I know you cant subtract alias' Any thoughts?
((char(current time + 7 HOURS + 30 MINUTES) -(char(theDelivery + 100 DAYS)))


So i figured out i was going all wrong with char's. I came up with this and it was exactly what i was looking for:

SELECT theDelivery,
TIMESTAMP(theDelivery, current time) AS Begin
,
TIMESTAMP((theDelivery + 100 DAYS), (current time + 7 HOURS + 30 MINUTES)) AS End,
TIMESTAMP((theDelivery + 100 DAYS), (current time + 7 HOURS + 30 MINUTES)) - TIMESTAMP(theDelivery, current time) AS MyDur

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苄①跕圉湢 2024-12-17 09:45:32

如果您这样做:

((char(current time + 7 HOURS + 30 MINUTES) -(char(theDelivery + 100 DAYS)))

您正在减去字符。您可以尝试:

date( 
  to_date(
      char(current time + 7 HOURS + 30 MINUTES),
      'YYYY-MM-DD HH.MI.SS'
  ) 
) -
date(
   to_date(
      char(theDelivery + 100 DAYS),
      'YYYY-MM-DD HH.MI.SS'
   )
)

或者在单行中:

date( to_date( char(current time + 7 HOURS + 30 MINUTES),'YYYY-MM-DD HH.MI.SS' ) ) - date( to_date(char(theDelivery + 100 DAYS),'YYYY-MM-DD HH.MI.SS') )

If you do:

((char(current time + 7 HOURS + 30 MINUTES) -(char(theDelivery + 100 DAYS)))

You are substracting chars. You can try:

date( 
  to_date(
      char(current time + 7 HOURS + 30 MINUTES),
      'YYYY-MM-DD HH.MI.SS'
  ) 
) -
date(
   to_date(
      char(theDelivery + 100 DAYS),
      'YYYY-MM-DD HH.MI.SS'
   )
)

Or in a sigle line:

date( to_date( char(current time + 7 HOURS + 30 MINUTES),'YYYY-MM-DD HH.MI.SS' ) ) - date( to_date(char(theDelivery + 100 DAYS),'YYYY-MM-DD HH.MI.SS') )
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文