我有这个查询:
return DB::table('electricity_meters')
->where('electricity_meters.id', 16)
->leftJoin('service_instances', 'service_instances.electricity_meter_id', '=', 'electricity_meters.id')
->leftJoin('readings', 'electricity_meters.kwh_param_id', '=', 'readings.parameter_id')
->where('readings.taken_at', '>', 'service_instances.active_to')
->select([
'readings.taken_at',
'service_instances.active_to',
])
->get();
注意'readings.taken_at', '>', 'service_instances.active_to'
,但不知何故结果是......
[
{
taken_at: "2021-02-16 23:59:59",
active_to: "2021-03-28"
},
...
]
我在这里遗漏了什么?
答案 0 :(得分:2)
我认为您想在两列之间进行比较,如果是这样,您应该使用 whereColumn:
return DB::table('electricity_meters')
->where('electricity_meters.id', 16)
->leftJoin('service_instances', 'service_instances.electricity_meter_id', '=', 'electricity_meters.id')
->leftJoin('readings', 'electricity_meters.kwh_param_id', '=', 'readings.parameter_id')
->whereColumn('readings.taken_at', '>', 'service_instances.active_to')
->select([
'readings.taken_at',
'service_instances.active_to',
])
->get();