【发布时间】:2020-06-28 15:23:11
【问题描述】:
查询时,我想使用 store_id 而不是 nd_001_store_id。我收到如下错误 production.ERROR: SQLSTATE[42S22]: Column not found: 1054 Unknown column 'store_id' in 'where clause'
$user_store_id = Session::get('user_store_id'); //for example 6
$a = "2020-06-20 13:00:00";
$b = "2020-07-05 13:00:00";
$sales_types = ['retail', 'wholesale'];
$invoice_items_stock_ids = InvoiceItems::select(
'nd_001_stock_id AS stock_id',
'nd_000_store_id AS store_id',
DB::raw("CONCAT(add_date_store, ' ', add_hours_store) AS date_range")
)->where(function ($query) use ($user_store_id) {
$query->where('store_id', '=', $user_store_id);
})->orWhere(function ($query) use ($a, $b) {
$query->where('date_range', '>=', $a)
->where('date_range', '<=', $b);
})
->whereIn('type', $sales_types)->get();
date_range 和 store_id 列未找到错误
谢谢, 最好的问候
【问题讨论】:
-
date_range 和 store_id 列在 InvoiceItems 表中吗?
-
您的 where 查询正在查找
store_id列。您应该可以直接查询nd_000_store_id。->where('nd_000_store_id', $user_store_id). -
@OMR 没有。我使用了 'nd_000_store_id AS store_id' 和 DB::raw("CONCAT(add_date_store, ' ', add_hours_store) AS date_range")。表中有nd_000_store_id、add_date_store、add_hours_store列