gpt4 book ai didi

php - 从 mysql 表中获取先前不存在的当前日期详细信息

转载 作者:行者123 更新时间:2023-11-29 23:13:55 24 4
gpt4 key购买 nike

我有一个 mysql 表,每天都会加载生产数据。我需要一列值(推荐),这些值在较早的日期中不存在,即当前日期 -1

我尝试过各种查询:

1)

select distinct referral from time_in_report where crt_date=curdate() and referral not in(select distinct referral from time_in_report where crt_date<curdate())

上面的查询是正确的,但是由于表中数据量很大,因此需要很长时间才能响应并且会耗尽内存。所以我不能使用上面的查询

2)

select distinct referral from time_in_report a where a.crt_date=curdate() and not exist(select 1 from time_in_report b where a.id=b.id and b.crt_date<curdate())

在上面的查询中,ID 列是表中的主键。由于一个推荐可以有不同的ID,因此上述查询结果不正确。我收到了一些推荐,这些推荐存在于当前日期之外的先前日期。

  • 从 time_in_report a 中选择不同的引用,其中 a.crt_date=curdate()减从 time_in_report a 中选择不同的引荐,其中 a.crt_date

  • Minus 在我的 mysql 版本中不起作用。

    请就如何获得当前日期的独特推荐提出您的想法,该推荐不会出现在除当前日期之外的其他日期。

    提前致谢

    最佳答案

    您可以检查不等于当前日期的字段,而不是减去当前日期。

    select distinct referral from time_in_report where crt_date=curdate() and referral not in(select distinct referral from time_in_report where crt_date!=curdate());

    试试这个。

    关于php - 从 mysql 表中获取先前不存在的当前日期详细信息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27948637/

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