如何把foreach中的sql语句写成一个子查询放入上面的sql语句中 5
$sql="selectsd.user_iduserId,u.test_codetestCode,COUNT(u.test_code)testCodeCount,sd.u...
$sql = "select sd.user_id userId,u.test_code testCode,COUNT(u.test_code) testCodeCount,sd.user_name as userName,sd.real_name as realName ,sd.mobile_phone as mobilePhone from ".$ecs->table('users')." u inner join ".$ecs->table('share_data'). "sd on u.test_code=sd.test_code where 1=1 $where group by u.test_code limit ".($filter['page'] - 1)* $filter['page_size'].",".$filter['page_size'];
$res = $db->getAll($sql);
foreach($res as $k=>$uInfo){
$sql = "select count(oi.order_id) orderCount,sum(oi.money_paid) sumMoneyPaid from ".$ecs->table('order_info')." oi inner join ".$ecs->table('users')." u on u.user_id = oi.user_id where oi.order_status<>4 and order_status<>2 and pay_status<>0 and u .test_code='$uInfo[testCode]'$where2 and add_time>datetime"; 展开
$res = $db->getAll($sql);
foreach($res as $k=>$uInfo){
$sql = "select count(oi.order_id) orderCount,sum(oi.money_paid) sumMoneyPaid from ".$ecs->table('order_info')." oi inner join ".$ecs->table('users')." u on u.user_id = oi.user_id where oi.order_status<>4 and order_status<>2 and pay_status<>0 and u .test_code='$uInfo[testCode]'$where2 and add_time>datetime"; 展开
1个回答
2018-07-24 · 百度认证:云南新华电脑职业培训学校官方账号
云南新华电脑学校
云南新华电脑学校是经云南省教育厅批准成立的省(部)级重点计算机专业学校,采用三元化管理模式,教学设备先进,师资雄厚学生毕业即就业,学院引进了电商企业入驻,创建心为电商创业园区,实现在校即创业
向TA提问
关注
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询