【求助】TP5 这段代码怎么写成链式操作

清指引我前行 2019-04-12 10:34:31
select * from a as tab1
left join b as tab2
on tab1.id = tab2.kehu_id
where (tab1.status=1 and tab2.status =3)
or (tab1.status=1 and tab2.status is NULL)
...全文
1016 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
清指引我前行 2019-04-19
  • 打赏
  • 举报
回复
有大佬吗
下雨的声音丶 2019-04-19
  • 打赏
  • 举报
回复

Db::table('a')
            ->alias('tab1')
            ->join('b tab2','tab1.id = tab2.kehu_id', 'LEFT')
            ->where(function($query) use ($map){
                $query->where($map);
            })
            ->whereOr(function($query){
                $query->where('tab1.status', 1)->whereNull('tab2.status');
            })
            ->select();
清指引我前行 2019-04-17
  • 打赏
  • 举报
回复
引用 4 楼 m0_37738733 的回复:
这个简单

        Db::table('a')
            ->alias('tab1')
            ->join('b tab2','tab1.id = tab2.kehu_id')
            ->where('(tab1.status=1 AND tab2.status=3) OR (tab1.status=1 AND tab2.status is NULL)')
            ->select();
我的意思是写成这种

$map['tab1.status']=1;
$map['tab2.status']=3
        Db::table('a')
            ->alias('tab1')
            ->join('b tab2','tab1.id = tab2.kehu_id')
            ->where($map)
            ->select();
$map怎么写
m0_37738733 2019-04-17
  • 打赏
  • 举报
回复
引用 6 楼 清指引我前行 的回复:
[quote=引用 4 楼 m0_37738733 的回复:] 这个简单

        Db::table('a')
            ->alias('tab1')
            ->join('b tab2','tab1.id = tab2.kehu_id')
            ->where('(tab1.status=1 AND tab2.status=3) OR (tab1.status=1 AND tab2.status is NULL)')
            ->select();
我的意思是写成这种

$map['tab1.status']=1;
$map['tab2.status']=3
        Db::table('a')
            ->alias('tab1')
            ->join('b tab2','tab1.id = tab2.kehu_id')
            ->where($map)
            ->select();
$map怎么写[/quote] or里面有AND这种情况我也没在手册里找到
乖别闹哦 2019-04-16
  • 打赏
  • 举报
回复
.编程+ 编写程序,求e的值。e 1+1/1!+1/21+1/3.+1/4/+*.+1/n!(1)用for循环,计算前50项。 (2)用while循环,要求直至最后一项的值小于10-64[源程序] +For循环: 谁会这个,我没有积分,发不了帖子┐(´-`)┌
m0_37738733 2019-04-16
  • 打赏
  • 举报
回复
这个简单

        Db::table('a')
            ->alias('tab1')
            ->join('b tab2','tab1.id = tab2.kehu_id')
            ->where('(tab1.status=1 AND tab2.status=3) OR (tab1.status=1 AND tab2.status is NULL)')
            ->select();
清指引我前行 2019-04-15
  • 打赏
  • 举报
回复
还是没有大神吗?
清指引我前行 2019-04-12
  • 打赏
  • 举报
回复
主要是or里面的tab2.status is NULL操作不来
清指引我前行 2019-04-12
  • 打赏
  • 举报
回复
在线等

21,886

社区成员

发帖
与我相关
我的任务
社区描述
从PHP安装配置,PHP入门,PHP基础到PHP应用
社区管理员
  • 基础编程社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧