0

我想为特定的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 |
+-----------+----------+----------+---------------------+
4

2 回答 2

0

使用类似的东西:

SET @dte:=CURRENT_DATE();
SELECT DATEDIFF(Created, @dte),@dte:=Created FROM table ORDER BY Created

这将显示两个值之间的差异(第一条记录除外)。您可以添加一个额外的 IF 或者只是不显示第一个日期。

于 2012-10-09T13:58:20.410 回答
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";
于 2013-05-14T19:43:17.387 回答