【发布时间】:2019-11-15 06:21:29
【问题描述】:
这是一个性能好的查询还是我可以以某种方式优化这个查询?我需要从rental_schedules 表中选择日期列并计算有多少可用的相同日期可用(rental_schedule_status = 1):
$reservationTimes = RentalSchedule::distinct()
->select('date',
DB::raw('(SELECT count(date) FROM rental_schedules AS r2
WHERE r2.date = rental_schedules.date and rental_schedule_status = 1) as free_time'))
->where('premises_id', $id)->pluck('free_time', 'date');
提前致谢!
【问题讨论】: