问题是这样的有一个orders表,里面有ID,userID,enddate,start_date,paymethod,bill_acount,productsenddate是产品的终止日期,startdate是产品的开始日期,paymethod是付款状态,里面...
问题是这样的
有一个orders表,里面有ID,userID,enddate,start_date,paymethod,bill_acount,products
enddate是产品的终止日期,startdate是产品的开始日期,paymethod 是付款状态,里面有freetrial和paid状态,bill_acount是金额,products是产品
现在我需要查询所有终止日期在某一段时间的试用者转购买的人数,分产品
其中要注意到是,有些用户同时使用几个产品,但是分开算,每个产品,可能有多条记录,但是userID是一样的,另外,paid,可能有几次付款记录,
这个是我做的,不过得到的不是我要的,可以参考一下
select o2.* from orders o1,orders o2
where o1.user_id in (select user_id from orders where pay_method="free trial" and date_format(o1.end_date,"%Y%m%d") between 20080825 and 20080831)
and o2.pay_status="paid"
and o1.user_id=o2.user_id
and o1.product_id=o2.product_id
order by user_id
另外还需要注意的是,有些PAID是续费,也就是说客户在多个产品里有注册,有些是试用,有些是已经购买的,有些购买的日期正好在这个区间里,但是产品不一样
确实有点模糊
现在我给你案例,比如现在有产品A,B,C,D四个产品,用户1在8月25号之前就应该购买了A和B的产品,并有多次付款记录,C是试用,A和C的enddate终止日期是在8月25-8月31之间,我现在要知道的是用户1在试用了C之后有没有购买,而ABD,是不重要的,无关的数据
我最终要统计的是有多少用户的在试用期(8.25-8.31)终结的这段时间,或之后会购买对应的产品
展开