tmkutvpkwtsql語句博大精深
理解好sql語句,就能用好thinkphp等框架中的資料庫操作
原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_opewww.cppcns.comner a
left join sh_opener_bonus b on a.id = b.opener_id
left join sh_incentive c on b.incentive_id = c.id
whewww.cppcns.comre 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;
這裡面有兩個子查詢語句,其實子查詢語句也是表,只不過是存在記憶體中罷了。
thinkphp實現:
$useyear = date('y',strtotime('last month'));
$this->assign('useyear',$useyear);
$usemonth = date('m',strtotime('last month'));
$this->assign('usemonth',$usemonth);
// 獲取上一月人員的獎金金額
// 子查詢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);www.cppcns.com
// 子查詢tmkutvpkwt2
$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);
其實thinkphp框架對sql的封裝,最終還是要拼湊成sql語句。
C 實現多個子窗體切換
1.設定mdi主選單的mdiwindowlistitem 顯示子視窗的選單tsmiwindow,這樣開啟的子窗體標題將自動顯示在window選單下 private void tsmiwindownext click object sender,eventargs e else private voi...
同步移動多個子視窗
移動子視窗,一般會引起父視窗重繪,如果多個子視窗單個移動就會導致父視窗多次重繪效率較低,win32中提供了一種一次移動多個視窗的一組api hdwp begindeferwindowpos intnnumwindows 指定帶移動的視窗數 hdwp deferwindowpos hdwphwinpo...
hover 控制多個子div
一 通過css方式來控制hover實現控制多個子div 產品經理 最激動人心的是,是將想法實現,並被數千使用者所使用 申請職位 產品經理 joson 產品經理 運營的重點不只是營業額,而是讓使用者在這裡獲得更多樂趣 申請職位 運營經理 joson 研發工程師 研發工程師可以參與產品的設計,寫 也可以...