如上图所示, 用到的字段 有 uid(用户id) pid(直接推荐人ID) ppid(间接推荐人ID) fen(销售份数) addtime(购买的时间)要求为统计所有 pid ppid uid 的销售份数总和按时间段来排序.说明 三级分销的业绩是累加的. 也就是要把这个表中所有 pid,ppid,uid为同一个id值的时候统计出销售份数之和,并排序.想问下这个能实现么. (目前仅能得到单个字段的统计结果)$time1 $time2 是起止时间"SELECT uid,SUM(fen) as fen FROM yh_sales WHERE addtime BETWEEN $time1 AND $time2 GROUP BY 1 ORDER BY 2 DESC LIMIT 0 , 5"
1 回答
已采纳
是王小二呀
TA贡献88条经验 获得超19个赞
select id,sum(counts) as total from ( select pid as id,sum(fen) as counts from yh_sales group by pid union all select ppid as id,sum(fen) as counts from yh_sales group by ppid union all select uid as id,sum(fen)as counts from yh_sales group by uid) tab group by id
没搞明白你这个按照时间排序,是按照谁的时间? pid?uid?ppid?,自己看着join一下再选时间【】排一下序吧。
添加回答
举报
0/150
提交
取消