我有一个表有4个字段列; id,cinema_id,movie_id,showing_at。
id - Integer(primary key)
cinema_id - Integer(foreign key)
movie_id - Integer(foreign key)
showing_at - Datetime
我试图提出一个查询,该查询根据movie_id列和日期从表中检索结果,并使用cinema_id对结果进行分组; 我当前的查询使用laravel
看起来像这样$models = DB::table('showtimes')->where('movie_id', $movie_id)
->whereBetween('showing_at', [$date." 00:00", $date." 23:00"])
->groupBy('cinema_id')
->get();
转储的查询结果如下所示
Array
(
[0] => stdClass Object
(
[id] => 161
[cinema_id] => 1
[movie_id] => 15
[showing_at] => 2016-03-20 12:20:00
[created_at] =>
[updated_at] =>
)
[1] => stdClass Object
(
[id] => 145
[cinema_id] => 3
[movie_id] => 15
[showing_at] => 2016-03-20 10:00:00
[created_at] =>
[updated_at] =>
)
)
如何查询数据库以对cinema_id
下的所有放映时间进行分组