gpt4 book ai didi

sql - 需要有关 SQL 查询的帮助以提取数据

转载 作者:行者123 更新时间:2023-12-01 15:11:55 25 4
gpt4 key购买 nike

我编写的 SQL 查询检索了 3677 行,其中 cutomerID 字段包含许多重复数据。我想编写查询,它将给我以下所有必填字段,仅具有唯一的 cutomerID。我们不能仅对 customerID 使用 distinct,因为其他字段具有不同的数据类型。请协助我查询:

  SELECT TimeMark,
CustomerID,
AccountId,
TargetURL
FROM BTILog
WHERE timemark BETWEEN '20140926 00:00:00'
AND '20141020 23:59:59'
AND TargetURL LIKE '%/api/v1/cust/details%'
AND Class LIKE 'com.btfin.security.sso.SSODetailsFactory%'
ORDER BY TimeMark DESC

Please have a look the data I am getting from the below query. There you can see duplicate customerID as highlighted in blue line. I want the 57155299 customer only once with last time mark, similarly if there will be any other customer who have appeared twice/thrice or so on, theey should only once in my data extract

最佳答案

您应该在 TimeMark 上使用分组依据和聚合功能。以下将为您提供唯一的客户 ID 记录以及每个记录的最后输入时间标记:

SELECT max(TimeMark) TimeMark,
CustomerID,
AccountId,
TargetURL
FROM BTILog
WHERE timemark BETWEEN '20140926 00:00:00'
AND '20141020 23:59:59'
AND TargetURL LIKE '%/api/v1/cust/details%'
AND Class LIKE 'com.btfin.security.sso.SSODetailsFactory%'
GROUP BY CustomerID, AccountId,TargetURL
ORDER BY TimeMark DESC

关于sql - 需要有关 SQL 查询的帮助以提取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26491095/

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