1

我有一个名为的表active_plans,其中有两列:activated_datelast_billed_at. 基本上,我想创建一个查看这两列的查询,如下所示:

select all from active_plans 
          where last_billed_at = null AND activated_date + 1 month = today, 
          or if last_billed_at + 1 month = today.

不过,我似乎无法弄清楚如何做到这一点。

4

1 回答 1

0

我最终做了很多不同的事情: public function getBillToday() { $activePlans = $this->entityManager ->createQuery('SELECT adp FROM adp WHERE adp.activationDate IS NOT NULL') ->getResult(); $数据 = 数组();

    foreach ($activePlans as $plan) {
        $recur = $plan->getPlan()->getRecurringInMonths();
        $nextBillTime = strtotime('-'.$recur.' months', time());
        $nextBill = date('Y-m-d', $nextBillTime);
        $activationDate = $plan->getActivationDate();
        $lastBilledAt = $plan->getLastBilledAt() != NULL ? $plan->getLastBilledAt()->format('Y-m-d') : 0;
        if ($activationDate == $nextBill || $lastBilledAt == $nextBill) {
            $data[] = $plan->getId();
        }
    }

    return $data;
}
于 2013-04-02T14:04:17.817 回答