最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

thinkPHP簡(jiǎn)單實(shí)現(xiàn)多個(gè)子查詢語(yǔ)句的方法

 更新時(shí)間:2016年12月05日 11:59:55   作者:牛逼的霍嘯林  
這篇文章主要介紹了thinkPHP簡(jiǎn)單實(shí)現(xiàn)多個(gè)子查詢語(yǔ)句的方法,結(jié)合實(shí)例形式對(duì)比分析了thinkPHP中子查詢語(yǔ)句的具體實(shí)現(xiàn)技巧,需要的朋友可以參考下

本文實(shí)例講述了thinkPHP簡(jiǎn)單實(shí)現(xiàn)多個(gè)子查詢語(yǔ)句的方法。分享給大家供大家參考,具體如下:

sql語(yǔ)句博大精深

理解好sql語(yǔ)句,就能用好thinkphp等框架中的數(shù)據(jù)庫(kù)操作

原sql:

SELECT a.*,b.* from (SELECT a.id as opener_id,a.name,sum(c.money) as bonus_money,c.year,c.month from sh_opener a
LEFT JOIN sh_opener_bonus b on a.id = b.opener_id
LEFT JOIN sh_incentive c on b.incentive_id = c.id
where a.agent_id = 3 and a.status = 1 and c.year = 2015 and c.month = 11
GROUP BY a.id,c.year,c.month) a
LEFT JOIN (SELECT a.id as payment_id,a.opener_id,a.money as payment_money,a.trode_number from sh_opener_bonus_payment a
where a.year = 2015 and a.`month` = 11 and a.agent_id = 3) b
on a.opener_id = b.opener_id;

這里面有兩個(gè)子查詢語(yǔ)句,其實(shí)子查詢語(yǔ)句也是表,只不過(guò)是存在內(nèi)存中罷了。

thinkphp實(shí)現(xiàn):

$useYear = date('Y',strtotime('last month'));
$this->assign('useYear',$useYear);
$useMonth = date('m',strtotime('last month'));
$this->assign('useMonth',$useMonth);
// 獲取上一月人員的獎(jiǎng)金金額
// 子查詢1
$whereSub1['a.agent_id'] = $this->agent_id;
$whereSub1['a.status'] = 1;
$whereSub1['c.year'] = $useYear;
$whereSub1['c.month'] = $useMonth;
$subQuery1 = M()->table('sh_opener a')->join('sh_opener_bonus b on a.id = b.opener_id')->join('sh_incentive c on b.incentive_id = c.id')->where($whereSub1)->group('a.id,c.year,c.month')->field('a.id,a.name,sum(c.money) as bonus_money,c.year,c.month')->select(false);
// 子查詢2
$whereSub2['a.agent_id'] = $this->agent_id;
$whereSub2['a.year'] = $useYear;
$whereSub2['a.month'] = $useMonth;
$subQuery2 = M()->table('sh_opener_bonus_payment a')->where($whereSub2)->field('a.id as payment_id,a.opener_id,a.money as payment_money,a.trode_number')->select(false);
$list = M()->table($subQuery1.' a')->join($subQuery2.' b on a.id = b.opener_id')->select();
$this->assign('list',$list);

其實(shí)thinkphp框架對(duì)sql的封裝,最終還是要拼湊成sql語(yǔ)句。

更多關(guān)于thinkPHP相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《ThinkPHP入門教程》、《thinkPHP模板操作技巧總結(jié)》、《ThinkPHP常用方法總結(jié)》、《codeigniter入門教程》、《CI(CodeIgniter)框架進(jìn)階教程》、《Zend FrameWork框架入門教程》、《smarty模板入門基礎(chǔ)教程》及《PHP模板技術(shù)總結(jié)》。

希望本文所述對(duì)大家基于ThinkPHP框架的PHP程序設(shè)計(jì)有所幫助。

相關(guān)文章

最新評(píng)論

祁东县| 墨竹工卡县| 勃利县| 南开区| 鸡东县| 宝鸡市| 梅河口市| 韩城市| 天台县| 贵定县| 长顺县| 沙河市| 绿春县| 呈贡县| 永顺县| 安岳县| 正安县| 清镇市| 朝阳区| 瓮安县| 呼和浩特市| 婺源县| 宜兴市| 广河县| 简阳市| 德化县| 吉木萨尔县| 讷河市| 二连浩特市| 彭山县| 庆城县| 中牟县| 保靖县| 宁武县| 上蔡县| 拉萨市| 扎鲁特旗| 确山县| 天门市| 阿合奇县| 威信县|