mysql函数DATE_ADD使用

      mysql提供了非常有用的函数DATE_ADD 。DATE_ADD() 函数向日期添加指定的时间间隔。

    语法:

DATE_ADD(date,INTERVAL expr type)   date 参数是合法的日期表达式。expr 参数是您希望添加的时间间隔 

 例如:

 从订单表中查询出六个月内下单的客户(正常客户),那么其他客户则是六个月未下单的客户。(流失客户为1)

select cusId from t_customer_order where DATE_ADD(orderDate,INTERVAL 6 MONTH)>NOW()   六个月内下单的客户

六个月内未下单的用户

select * from t_customer t1  where t1.id not in (select cusId from t_customer_order where DATE_ADD(orderDate,INTERVAL 6 MONTH)>NOW()) and state=0

 

 

 

 
posted @ 2017-09-16 17:42  心和梦的方向  阅读(2004)  评论(0编辑  收藏  举报