需要为每种类型的电子邮件找到发送日期和单击日期之间的时间差的中间值(以秒为单位)。我为所有数据找到了解决方案:
SET @rowindex := -1;
SELECT g.type, g.time_diff
FROM
(SELECT @rowindex:=@rowindex + 1 AS rowindex,
TIMESTAMPDIFF(SECOND, emails_sent.date_sent, emails_clicks.date_click) AS time_diff,
emails_sent.id_type AS type
FROM emails_sent inner join emails_clicks on emails_sent.id = emails_clicks.id_email
ORDER BY time_diff) AS g
WHERE g.rowindex IN (FLOOR(@rowindex / 2) , CEIL(@rowindex / 2));
是否可以添加group by id\u type语句?谢谢!
1条答案
按热度按时间qyyhg6bp1#
首先,需要枚举每种类型的行。使用变量,此代码如下所示:
然后,您需要输入每种类型的总数并计算中位数: