我想为特定的ticket_id采取停滞(NewValue)和停滞(OldValue)之间的“创建”时差
注意:这是我的第一篇文章。由于某些限制,我无法附加图片。
+-----------+----------+----------+---------------------+
| Ticket_id | OldValue | NewValue | Created |
+-----------+----------+----------+---------------------+
| 20100 | new | wip | 2012-10-01 07:38:18 |
| 20100 | wip | stalled | 2012-10-01 10:12:14 |
| 20100 | stalled | wip | 2012-10-01 22:09:39 |
| 20100 | wip | open | 2012-10-02 01:03:26 |
| 20100 | open | stalled | 2012-10-02 01:03:26 |
| 20100 | stalled | wip | 2012-10-03 06:55:42 |
| 20100 | wip | open | 2012-10-03 19:24:53 |
| 20100 | open | stalled | 2012-10-03 19:24:53 |
| 20100 | stalled | open | 2012-10-04 19:28:48 |
| 20100 | open | resolved | 2012-10-04 21:01:17 |
+-----------+----------+----------+---------------------+
答案 0 :(得分:0)
使用类似:
SET @dte:=CURRENT_DATE();
SELECT DATEDIFF(Created, @dte),@dte:=Created FROM table ORDER BY Created
这将显示两个值之间的差异(第一个记录除外)。您可以添加额外的IF或只是不显示第一个日期。
答案 1 :(得分:0)
这是我来的解决方案。我不确定你是否和JIRA合作,但我(看起来你可能是)。我需要找到特定JIRA票证保持特定状态的时间(尽管它已经改变的次数)。
SELECT
ThisLog.issueid,
b.NEWSTRING,
SUM(TIMESTAMPDIFF(HOUR,ThisLog.created,PrevLog.created)*-1) AS "Status Time"
FROM
changegroup AS ThisLog
LEFT JOIN
changegroup AS PrevLog
ON PrevLog.issueid = ThisLog.issueid
AND PrevLog.created = (SELECT MAX(created)
FROM changegroup
LEFT JOIN changeitem AS b1
ON changegroup.ID = b1.groupid
WHERE issueid = ThisLog.issueid
AND created < ThisLog.created
AND b1.field = "status"
AND b1.NEWSTRING = "Pending Customer")
LEFT JOIN changeitem AS b
ON ThisLog.ID = b.groupid
WHERE ThisLog.issueid = 82720 AND b.field = "status" AND b.NEWSTRING = "Pending Customer";