3表查询,1:多:多,根据1查多再查多
Posted guoyinglichong
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了3表查询,1:多:多,根据1查多再查多相关的知识,希望对你有一定的参考价值。
1个代理人对应多个用户,用户对应多个订单
原生sql语句
1 $result = $users->query("select orderid,money,tid,username,game,type,ordertime 2 from ( 3 (cmf_agent a inner join cmf_q_users b on a.id=b.agent_id) 4 inner join cmf_orders c on c.userid=b.id 5 )where( 6 agent_id = $agentid 7 )" 8 );
tp关联查询
1 $count1 = $users 2 ->field(‘orderid,money,tid,username,game,type,ordertime‘) 3 ->join(‘cmf_agent on cmf_q_users.agent_id = cmf_agent.id‘) 4 ->join(‘cmf_orders on cmf_orders.userid = cmf_q_users.id‘) 5 ->where($where) 6 ->count(); 7 // dump($count1); 8 9 $page = $this->page($count1, 10); 10 11 $result = $users 12 ->field(‘orderid,money,tid,username,game,type,ordertime‘) 13 ->join(‘cmf_agent on cmf_q_users.agent_id = cmf_agent.id‘) 14 ->join(‘cmf_orders on cmf_orders.userid = cmf_q_users.id‘) 15 ->where($where) 16 ->limit($page->firstRow . ‘,‘ . $page->listRows) 17 ->select();
以上是关于3表查询,1:多:多,根据1查多再查多的主要内容,如果未能解决你的问题,请参考以下文章