gpt4 book ai didi

mysql - sql查询获取最新的调用

转载 作者:行者123 更新时间:2023-11-29 09:42:21 25 4
gpt4 key购买 nike

有人能给我指出我需要阅读的正确方向吗? ...

我有两张 table 。第一个包含客户 ID 和客户姓名。第二个包含客户 ID 和调用客户的日期。我使用 LEFT JOIN 获取每个客户的列表,其中包含打给他的所有电话。像这样:

1, Max Mustermann, 2019-05-22
1, Max Mustermann, 2019-05-20 (<- I don't want this row to appear.)
2, Ilse Meier,

我也使用 LEFT JOIN 无需调用即可吸引客户。

现在我只想要最近一次调用的结果。

对于一个电话(获取最新信息)我可以这样做:

SELECT * FROM calls ORDER BY call_date DESC LIMIT 1;

我被困住了。我需要阅读什么内容?

最佳答案

您可以使用 group bymax() 来获取最新通话的客户。当客户从未调用时,Maxdateofcall 中将为 NULL

select 
t1.customerid
,t1.customername
,max(t2.dateofcall) as Maxdateofcall
from table1 t1 left join table1 t2 on t1.customerid = t2.customerid
group by t1.customerid ,t1.customername


1, Max Mustermann, 2019-05-22
2, Ilse Meier, null

关于mysql - sql查询获取最新的调用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56347518/

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