Yii 2.0 sql 语句优化 [ 2.0 版本 ]
select u.id,u.nickname,u.avatar_url,tt.count_order from user as u
left join (select o.user_id,count(o.user_id) as count_order from pt_order as o where
exists(select d.id from pt_order_detail as d where d.order_id=o.id and
exists(select g.id from pt_goods as g where g.id=d.goods_id and g.user_id=".$this->user_id."))
and o.is_success=1 and o.is_group
group by o.user_id) as tt on tt.user_id=u.id
where exists(select f.id from pt_follow as f where u.id = f.user_id and f.pt_user_id=".$this->user_id.")
表有pt_order(订单表) pt_goods(商品表) pt_follow(关注表) pt_order_detail(订单商品关联表) user(用户表)
目标: 查询下了该用户($this->user_id)的粉丝订单的数据
这句sql语句能否用yii2写?
共 1 个回答
wherein 广州
注册时间:2018-07-06
最后登录:2018-09-12
在线时长:3小时24分
最后登录:2018-09-12
在线时长:3小时24分
- 粉丝2
- 金钱690
- 威望0
- 积分720