我想根据laravel中的当前时间选择行。我有一个查询,但它给出一个空的结果。
$price_calc = DB::table('trip_price_fixing')
->select(DB::raw("DATE(D.datumTijd),
CASE WHEN TIME(D.datumTijd) BETWEEN '08:00:00' AND '14:00:00' THEN 1
WHEN TIME(D.datumTijd) BETWEEN '14:00:00' AND '20:00:00' THEN 2
WHEN TIME(D.datumTijd) BETWEEN '20:00:00' AND '24:00:00' THEN 3
END "));
答案 0 :(得分:0)
尝试在select中分隔字段并命名secound聚合字段(在我的示例中为result
):
$price_calc = DB::table('trip_price_fixing')
->select(DB::raw("DATE(D.datumTijd) as date",
DB::raw("(CASE WHEN TIME(D.datumTijd) BETWEEN '08:00:00' AND '14:00:00' THEN 1
WHEN TIME(D.datumTijd) BETWEEN '14:00:00' AND '20:00:00' THEN 2
WHEN TIME(D.datumTijd) BETWEEN '20:00:00' AND '24:00:00' THEN 3
END) as result"))->get();
我还认为你必须从查询中删除D.
命名空间。