-2

这是我的 sql 选择查询:

SELECT 
 contact_individual.name,contact_individual.contactID_individual,
 MAX(DATE_FORMAT(payment_individual.expiration,'%m/%d/%Y')) as exp1 
 FROM contact_individual,payment_individual
 WHERE contact_individual.contactID_individual = payment_individual.contactID_individual    
 group by contact_individual.contactID_individual,contact_individual.name
 having MAX(payment_individual.expiration)=DATE_ADD(current_date(), INTERVAL 1 MONTH)

在这种情况下,仅在到期日期为到期前 1 个月时才显示会员姓名。请帮助我,我想做的就是让它可用/或者是否可以在整个 30 天内显示成员的姓名。谢谢!

4

2 回答 2

0

也许这个?

HAVING MAX(payment_individual.expiration) BETWEEN
              NOW()
              AND DATE_ADD(NOW(), INTERVAL 1 MONTH)
于 2013-02-03T14:12:49.870 回答
0

如果您为原始结果和预期结果提供了一些示例数据,那就太好了。是不是要显示有效期在今天后一个月内的成员?

SELECT 
 contact_individual.name,contact_individual.contactID_individual,
 MAX(DATE_FORMAT(payment_individual.expiration,'%m/%d/%Y')) as exp1 
 FROM contact_individual,payment_individual
 WHERE contact_individual.contactID_individual = payment_individual.contactID_individual    
 group by contact_individual.contactID_individual,contact_individual.name
 having DATE_DIFF(MAX(payment_individual.expiration),Current_Date()) = 30
 ;
于 2013-02-03T14:14:58.763 回答