malike 发表于 2018-2-11 12:00:36


            本文实例讲述了thinkPHP简单实现多个子查询语句的方法。分享给大家供大家参考,具体如下:
sql语句博大精深
理解好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_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;
页: [1]
查看完整版本: thinkPHP简单实现多个子查询语句的方法