关于TP5模块下数据库查询的问题

问题描述

select * from tp_batch where final_time>$t and final_time<$s and status=1 or final_time>$s and final_time<$e;
在TP5框架下怎么写相当于这条语句?

阅读 1.6k
1 个回答

https://www.kancloud.cn/manua...

你需要用到的是这一页文档中的“混合查询”

Db::table('batch')->where(function ($query)  use ($t, $s)  {
    $query->where('final_time','>',$t)->where('final_time','<',$s)->where('status',1);
})->whereOr(function ($query) use ($t, $e) {
    $query->where('final_time','>',$t)->where('final_time','<',$e);
})->select();
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题