- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我有一个充当状态更改日志的数据库表。所有时间戳都在单个列中提供。我需要计算每个“on_id”的特定状态更改之间耗时(以分钟为单位)。正如您从我的示例数据中看到的,我不能简单地计算一行与下一行之间的差异,因为单个“on_id”的状态更改之间存在不相关的行。
id state from_state to_state start_time on_id user_id
45 transition_failed volunteer_to_donor claimed 2016-11-28 18:05:59.509807+00 10 53
1 transition_completed drafting available 2016-11-10 19:56:16.454458+00 2 12
2 transition_failed available available 2016-11-10 19:57:01.199609+00 2 12
3 transition_failed available available 2016-11-10 19:58:08.134549+00 2 12
28 transition_completed volunteer_to_donor volunteer_to_recipient 2016-11-22 22:14:57.060536+00 9 51
4 transition_completed drafting available 2016-11-14 16:36:17.802104+00 3 12
5 transition_completed drafting available 2016-11-16 14:59:56.925226+00 5 15
29 transition_failed volunteer_to_recipient volunteer_to_donor 2016-11-22 22:51:01.250038+00 9 51
6 transition_completed drafting available 2016-11-16 18:04:04.172773+00 6 15
7 transition_completed available claimed 2016-11-16 18:05:23.30427+00 6 16
30 transition_failed volunteer_to_recipient volunteer_to_recipient 2016-11-22 22:51:12.458881+00 9 51
8 transition_completed claimed volunteer_to_donor 2016-11-16 18:05:28.546312+00 6 16
9 transition_completed volunteer_to_donor volunteer_to_recipient 2016-11-16 18:05:39.388517+00 6 16
10 transition_failed volunteer_to_recipient volunteer_to_recipient 2016-11-16 18:05:48.772071+00 6 16
11 transition_completed volunteer_to_recipient complete 2016-11-16 18:06:56.9068+00 6 16
31 transition_completed volunteer_to_recipient complete 2016-11-22 22:51:38.570253+00 9 51
12 transition_completed drafting available 2016-11-21 15:11:01.842671+00 7 12
我认为我需要一个计算字段,但我无法弄清楚要使用的语法或函数。
例如,我希望能够计算每个“on_id”从“可用”状态到“已声明”状态所用的时间。对于 on_id 6,这需要 1 分 19 秒。
id state from_state to_state start_time on_id user_id
6 transition_completed drafting available 2016-11-16 18:04:04.172773+00 6 15
7 transition_completed available claimed 2016-11-16 18:05:23.30427+00 6 16
最佳答案
我在这里创建了示例表和 SQL:希望它有帮助。
Create table tbl(
Id int,
to_state varchar (10),
On_id int,
dte date);
Insert into tbl values ( 1, 'available', 6, '2018-02-22')
, ( 2, 'claimed' , 6 , '2018-02-25')
, ( 3, 'drafted' , 6 , '2018-02-23);
Sql:
Select distinct
t1.on_id,
t2.availstartdte,
t2.claimstartdte,
datediff(t2.claimstartdte, t2.availstartdte) as date_diff
From tbl t1
Join ( select id,
(Select Max(b.dte) from tbl b where b.to_state='available' and a.on_id=b.on_id) as availstartdte,
(Select Max(b.dte) from tbl b where b.to_state='claimed' and a.on_id=b.on_id) as claimstartdte
From tbl a
Where a.to_state in('available', 'claimed')
) t2
On t1.id = t2.id
结果:
on_id availstartdte claimstartdte date_diff
6 2018-02-22 2018-02-25 3
关于mysql - 根据 Tableau 中其他列的条件计算单列中的时间差,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48978336/
我对 EPOCH 时间有疑问。 我需要计算两个数据包之间的时间差。我不太确定如何: printf("Epoch Time: %d:%d seconds\n", header->ts.tv_sec, h
我正在尝试了解数字旋转的速度。我有一个程序,其中计数器从 0 开始。 每次用户单击按钮“加 1”。它将计数器递增 1。 计数器最大值为 255。在 255 之后它回到 0。 现在我想显示从 0 到递增
基本上我想做的是根据 SIP 信令获取通话持续时间。 我有一个包含如下所示记录的表,我正在尝试编写一个返回以下内容的 SELECT 语句: id callid date
您好,我需要有关 MySQL 数据库查询的帮助。 我有一个看起来像这样的表: ID TRACKID DATE Name Action 38
细节。我有包含以下列的注释表。 ID - INT(3) Date - DateTime Note - VARCHAR(100) Tile - Varchar(100
午夜过后我很难计算时间: String time = "15:00-18:05"; //Calculating OK //String time = "22:00-01:05"; //Not
我使用 XML 从 MySQL 数据库中抓取了两个日期,如下所示。我想获得以秒为单位的时差。 我写了这个脚本,但它给出了“NaN” function show(){ var t1 = new Dat
如何在 MYSQL phpMyAdmin 数据库中以 (TIME 00:00:00) 格式更新另一个字段(整列)的时间差 当我在 PHP 中执行此操作时,我不断收到 0:00:00 并且没有结果。其
我的表单中有两个字段,用户可以在其中选择输入时间(开始时间、结束时间),我想在更改这些字段时重新计算另一个字段的值。 我想做的是获取 2 次之间的小时数。因此,例如,如果我的开始时间为 5:30,结束
我想使用 Date 和 Calendar 类计算 java 中两个日期/时间之间的差异。我的格式是“2012-01-24 12:30:00 PM”。 我已经实现了我自己的方法,也用谷歌搜索它以与其他人
MySQL 服务器上的访客数据库如下所示id 是主键整数类型,firstname 和 lastname 是文本类型,访客 id 是整数类型 id firstname lastname
我是一名优秀的程序员,十分优秀!