根据表结构查询用户最新请求时间

问题: phonenumber 字段在 customer 表中,apiTime 字段在 api_log 表中。

解决方案: 以下是用 SQL 查询语句获取用户最新请求时间:

SELECT c.phonenumber, MAX(l.apiTime) AS latest_request_time
FROM customer c
JOIN api_log l ON c.customerId = l.customerId
WHERE c.phonenumber IN ('18988888888', '18966666666', '18905710006')
GROUP BY c.phonenumber;

解释:

  • 使用 JOIN 语句连接 customer 表和 api_log 表,通过 c.customerId = l.customerId 匹配关联。
  • 使用 WHERE 子句筛选特定的电话号码。
  • 使用 GROUP BYMAX 函数获取每个用户的最新请求时间。

结果: 查询结果将返回每个用户的电话号码和对应的最新请求时间。

注意: 根据实际的表结构和字段名,您可能需要进行适当的调整。

根据表结构查询用户最新请求时间

原文地址: https://www.cveoy.top/t/topic/ARy 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录