Код: Выделить всё
$productList = Product::select(
'ItemName'
,'ItemCode'
,'QryGroup64'
,'U_SDB_Image_File'
)->active();
if ($this->search) {
$productList = $productList->where('ItemName', 'LIKE', '%'. str_replace(" ", "%", $this->search) . '%');
}
if ($this->category) {
$productList = $productList->where('U_SDB_SALES_GROUP', $this->category);
}
// Handle the order by. It is done like this because of the pagination
if ($this->orderBy == 'ItemNameASC') {
$productList = $productList->with('customerSpecialPrice', 'bandAPrice', 'itemStock', 'itemsPurchased8Weeks')
->orderBy('ItemName');
} elseif ($this->orderBy == 'ItemNameDESC') {
$productList = $productList->with('customerSpecialPrice', 'bandAPrice', 'itemStock', 'itemsPurchased8Weeks')
->orderBy('ItemName', 'desc');
} elseif ($this->orderBy == 'PriceASC') {
$productList = $productList->with('itemStock', 'itemsPurchased8Weeks')
->withAggregate('bandAPrice', 'Price')
->withAggregate('customerSpecialPrice', 'Price')
->orderByRaw("COALESCE(customer_special_price_price, band_a_price_price)");
}
$productList = $productList->paginate($this->perPage);
Теперь, если я это сделаю:
Код: Выделить всё
->orderBy("customer_special_price_price");Ошибки, которые я получил:
При попытке: ->orderByRaw("COALESCE(customer_special_price_price,band_a_price_price)");, он выдает ошибку. Недопустимое имя столбца «customer_special_price_price».
Ниже приведен запрос, который он пытается выполнить, когда показывает эту ошибку:
Код: Выделить всё
select
top 20 [ ItemName ],
[ ItemCode ],
[ QryGroup64 ],
[ U_SDB_Image_File ],
(
select
top 1 Price
from
[ ITM1 ]
where
[ OITM ].[ ItemCode ] = [ ITM1 ].[ ItemCode ]
and [ PriceList ] = 25
) as [ band_a_price_price ],
(
select
top 1 Price
from
[ OSPP ]
where
[ OITM ].[ ItemCode ] = [ OSPP ].[ ItemCode ]
and [ CardCode ] = CF000097 - F
) as [ customer_special_price_price ]
from
[ OITM ]
where
SellItem = 'Y'
AND (
QryGroup64 = 'N'
OR OnHand > 0
)
and [ ItemName ] LIKE % carling %
order by
COALESCE(customer_special_price_price, band_a_price_price)
Подробнее здесь: https://stackoverflow.com/questions/790 ... y-coalesce
Мобильная версия