gpt4 book ai didi

mysql - 如何在MySQL中减去两个日期时间

转载 作者:行者123 更新时间:2023-11-29 10:32:41 25 4
gpt4 key购买 nike

我想统计购买前 7 天发生的着陆页浏览量。我使用了这个查询,它给出了一个错误

"cannot load from mysql.proc. the table is probably corrupted"

SELECT count(l.customer_id) FROM customer_profiles.purchase p
left join landingpage_view lp on lp.customer_id = p.customer_id
where lp.datetime between date_sub(p.datetime(), INTERVAL 7 Day) and p.datetime()
and lp.customer_id = '14475'

最佳答案

从语法正确的查询开始:

select count(*) 
from customer_profiles.purchase p join
landingpage_view lp
on lp.customer_id = p.customer_id
where lp.datetime between date_sub(p.datetime(), interval 7 Day) and p.datetime() and
lp.customer_id = 14475;

唯一会影响错误的更改是在 count() 中。别名 l 未定义。

其他更改:

  • 您也可以使用count(*)。不需要计算列数,因为您似乎想要计算行数。
  • where 子句将左联接 转换为内联接。因此,请使用查询真正执行的join
  • 我猜测 customer_id 是一个数字,因此我删除了单引号。

关于mysql - 如何在MySQL中减去两个日期时间,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47093094/

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