2
SELECT CTT.BAN, `Company`, `CID`, `FName`, `MInit`, 
   `LName`, `OName`, `Address`, `City`, `State`, 
   `PostalCode`, `ActiveDate`, `ClosedDate`, `Draft`, 
   `Credit`, `BillingCycle`, `BillingFreq`, `Suspended`, 
   `Paperless` , BTT.Bal 
FROM CustomerT CTT
  JOIN BalanceT BTT
ON (CTT.BAN = BTT.BAN)
WHERE  `Paperless` !=  '1'
   AND `BankDraft` != -1
   AND `CreditCard` != -1
   AND (`BillingCycle` = '1' OR `BillingCycle` = '0')
   AND `Bal` > 2 
   AND (`AccountClosedDate` IS NULL OR 
            DATE(`AccountClosedDate`) >= (NOW() - INTERVAL 180 DAY)  )

一切都适用于这个查询,但是 180 date peice 我已经从这个站点尝试了几件事,但没有运气。我只需要在表格中包含过去 6 个月的关闭帐户。

4

1 回答 1

4

用DATE_ADD试试这个

SELECT CTT.BAN, `Company`, `CID`, `FName`, `MInit`, `LName`, `OName`, `Address`, `City`, `State`, `PostalCode`, `ActiveDate`, `ClosedDate`, `Draft`, `Credit`, `BillingCycle`, `BillingFreq`, `Suspended`, `Paperless` , BTT.Bal 
FROM CustomerT CTT
JOIN BalanceT BTT ON
(CTT.BAN = BTT.BAN)
WHERE  `Paperless` !=  '1'
AND `BankDraft` != -1
AND `CreditCard` != -1
AND (`BillingCycle` = '1' OR `BillingCycle` = '0')
AND `Bal` > 2 
AND (`AccountClosedDate` IS NULL OR DATE(`AccountClosedDate`) >=DATE_ADD(CURDATE(), INTERVAL -180 DAY))

或使用( CURDATE() - INTERVAL 180 DAY )

SELECT CTT.BAN, `Company`, `CID`, `FName`, `MInit`, `LName`, `OName`, `Address`, `City`, `State`, `PostalCode`, `ActiveDate`, `ClosedDate`, `Draft`, `Credit`, `BillingCycle`, `BillingFreq`, `Suspended`, `Paperless` , BTT.Bal 
FROM CustomerT CTT
JOIN BalanceT BTT ON
(CTT.BAN = BTT.BAN)
WHERE  `Paperless` !=  '1'
AND `BankDraft` != -1
AND `CreditCard` != -1
AND (`BillingCycle` = '1' OR `BillingCycle` = '0')
AND `Bal` > 2 
AND (`AccountClosedDate` IS NULL OR DATE(`AccountClosedDate`) >=( CURDATE() - INTERVAL 180 DAY ))
于 2013-09-26T18:42:45.267 回答