gpt4 book ai didi

mysql - 使用时间戳从日志表中选择最新行

转载 作者:行者123 更新时间:2023-11-29 14:26:53 25 4
gpt4 key购买 nike

我有一个用于记录 Facebook 应用程序用户操作的表。我想要获取特定操作 ID 不早于 9 分钟的最新行。该表有很多其他统计信息列,因此我将仅显示代表问题的 2 行:

timestamp                  facebookID   producerID      eventID   actionID   numOfTickets
2012-05-28 13:16:38 100003286974944 9 1741 cpf 2
2012-05-28 13:16:13 100003286974944 9 1741 cpf 4

我想要做的是获取 actionID = 'cpf' 的最新行。

我尝试过的是:

SELECT CONCAT_WS(' ', y.firstName, y.lastName) as fullName, x.facebookID, x.numOfTickets, MAX(x.timestamp) 
FROM E4S_ANALYTICS.e4s_analytic_data x INNER JOIN E4S_FB.e4s_user_details y ON x.facebookID = y.facebookID
WHERE (x.actionID = 'CPF' AND x.numOfTickets > 0 AND x.producerID = 9 AND TIMEDIFF(NOW() , x.timestamp) < '00:09:00'
AND x.facebookID IN (SELECT facebookID FROM E4S_FB.e4s_session_data WHERE
TIMEDIFF(NOW() , sessionStart) < '00:09:00' ))

查询结果为:

facebookID      numOfTickets    MAX(x.timestamp)
100003286974944 4 2012-05-28 13:16:38

返回的时间戳是正确的,但 numOfTickets 是 4 而不是 2。

请注意,内部查询:

SELECT facebookID FROM  E4S_FB.e4s_session_data 
WHERE TIMEDIFF(NOW() , sessionStart) < '00:09:00' ))

用于查看谁仍然登录到应用程序。

最佳答案

SELECT CONCAT_WS(' ', y.firstName, y.lastName) AS fullName,
x.facebookID,
x.numOfTickets,
x.timestamp
FROM (
SELECT *
FROM E4S_ANALYTICS.e4s_analytic_data
WHERE actionID = 'cpf'
AND numOfTickets > 0
AND producerID = 9
AND TIMEDIFF(NOW() , timestamp) < '00:09:00'
AND (facebookID, timestamp) IN (
SELECT facebookID, MAX(timestamp)
FROM E4S_ANALYTICS.e4s_analytic_data
WHERE actionID = 'cpf'
AND numOfTickets > 0
AND producerID = 9
AND TIMEDIFF(NOW() , timestamp) < '00:09:00'
AND facebookID IN (
SELECT facebookID
FROM E4S_FB.e4s_session_data
WHERE TIMEDIFF(NOW() , sessionStart) < '00:09:00'
)
GROUP BY facebookID
)
) AS x
INNER JOIN E4S_FB.e4s_user_details AS y USING (facebookID)

关于mysql - 使用时间戳从日志表中选择最新行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10784045/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com