在sql Query中的laravel unknown列

时间:2015-07-25 06:03:58

标签: sql laravel-4

'having clause'.column中的未知列'erp_purchase_order_details.received'出现在表格中,但它显示上述错误

代码:

$status_result = DB::table('erp_purchase_order_details')->select(DB::raw('COUNT(erp_purchase_order_details.product_category_id) as count_products'),DB::raw('COUNT(erp_purchase_order_details.received) as count_received'))
        ->havingRaw('erp_purchase_order_details.received > 1')
        ->where('erp_purchase_order_details.purchase_order_id','=',$purchase_order_id)
        ->get();

1 个答案:

答案 0 :(得分:0)

HAVING子句条件中,您应该只使用聚合函数,而不是:

->havingRaw('erp_purchase_order_details.received > 1')

如果条件是关于列的,则将其移至WHERE子句,否则使用适当的聚合函数,如COUNT等。