编程语言
首页 > 编程语言> > thinkphp5 多表查询条件 or 和and 查询匿名函数

thinkphp5 多表查询条件 or 和and 查询匿名函数

作者:互联网

需要这样的sql效果

SELECT `a`.*,`user_name`,`dept_id` FROM `studentwork_leave` `a` LEFT JOIN `users` `u` ON `a`.`stu_id`=`u`.`user_id` WHERE ( ( `time_start` BETWEEN '2022-03-20 08:35' AND '2022-03-21 22:35' OR `time_end` BETWEEN '2022-03-20 08:35' AND '2022-03-21 22:35' ) OR ( (UNIX_TIMESTAMP(time_start)<=1647736500 AND UNIX_TIMESTAMP(time_end)>=1647873300) ) )

查询请假的数据 时间有穿插的问题

$model = model('Studentleave');
  $model->where('handle_status', 'lt', 2);

time_start 开始请假时间筛选 

$model->where(function ($query) use ($data) {
    $query->whereOr("time_start|time_end","between", [$data['time_start'],$data['time_end']]);
    $query->whereor('(UNIX_TIMESTAMP(time_start)<=' . strtotime($data['time_start']) . ' AND UNIX_TIMESTAMP(time_end)>=' . strtotime($data['time_end']) . ')');
});

标签:03,多表,thinkphp5,35,查询,start,time,end,data
来源: https://blog.csdn.net/hexiaoniao/article/details/123635832