先贴上语句
- {eval $beginYesterday=mktime(0,0,0,date('m'),date('d')-1,date('Y'));}
- {eval $endYesterday=mktime(0,0,0,date('m'),date('d'),date('Y'))-1;}
- {eval $sql ="SELECT SUM(a.`exta`) FROM a LEFT JOIN b ON a.`uid` = b.`uid` WHERE a.`exta` >= 100 AND b.`status` IN(2, 3) AND b.`xintime` >= $beginYesterday AND b.`xintime` <= $endYesterday GROUP BY b.`uid`");}
- {eval $meirisum = mysql_query($sql);}
- {eval list($sum)=mysql_fetch_row($meirisum);}
- {eval mysql_free_result($meirisum);}
- {eval $meiri=DB::fetch_all("SELECT d.`uid`,cast(d.`exta`/$sum as decimal(14, 13)) AS pp FROM c LEFT JOIN d ON c.`uid` = d.`uid` WHERE d.`exta` >= 100 AND c.`status` IN(2, 3) AND c.`xintime` >= $beginYesterday AND c.`xintime` <= $endYesterday GROUP BY c.`uid`");}
复制代码
想要的效果:找出满足a表内`exta`大于等于100并且b表内昨天存在`status`等于2或3数据的所有用户并对查询出来的a.`exta`求和赋值到$sum,然后再计算出每个满足要求的会员的`exta`占$sum的比例
相关附加信息:a表内结构和common_member_count表内一样,一个用户只有一行数据,而b表内满足条件的数据与a表内的用户不一定会一一对应,可能a表内`exta`大于等于100的用户,昨天在b表内没有数据或者有大于1条的数据,因为不能用嵌套(SELECT,所以不知道应该怎么弄
|