-1
该查询有效,但我首先需要它执行order by g1.caller , g1.created_on
。原因是我需要连续比较来电者,因此我可以看到他们是否必须多次致电以解决问题。如果需要通过查询运行之前执行订单
SELECT
g1.caller,
g1.created_on,
g1.config_item,
g2.caller,
g2.created_on,
g2.config_item
FROM
smp_newcall g1
INNER JOIN
smp_newcall g2 ON g2.id = g1.id + 1
WHERE
g1.caller = g2.caller and
g1.config_item = g2.config_item and
g1.created_on between '2017-07-01' and '2017-07-31'
奖励积分,你可以得到TIMESTAMPDIFF(HOUR,date(g1.created_on),date(g2.created_on)) > 48
在WHERE语句工作。目前它由于某种原因返回0。该列设置为datetime。
期望的返回数据应该是任何调用者,在同一个config_item的48小时内记录多个票据。
Row 1: John Smith, 2017-07-01 10:00:00, Outlook, John Smith, 2017-07-01 11:00:00, Outlook
Row 2: John Smith, 2017-07-02 11:00:00, Outlook, John Smith, 2017-07-03 11:00:00, Outlook
一旦我完成验证,但它只会返回计数。现在我想看到的是,48小时内同一个人,同样的事情。
SQL小提琴http://sqlfiddle.com/#!9/0d696/1 现在我知道数据已排序,我还有一个问题。它缺少2个回报。它也应该返回:
john doe 2017-07-01T11:00:00Z Windows 7 john doe 2017-07-02T10:00:00Z Windows 7
john smith 2017-07-01T11:00:00Z Outlook john smith 2017-07-02T10:00:00Z Outlook
请添加一些样本数据和样本预期结果。 –
完成。我需要这种排序的原因是,因为比较以前的行将无法正常工作。我们可以在中间接听来电,并且可以跨越多天。 – jerhynsoen
我们可以获得smp_newcall的表格模式和几个示例行吗?调用者和config_item的任何唯一标识符(以避免多个John Smith的情况)? – Joe