我尝试将查询转换为laravel
查询构建器,但我无法成功,我的查询位于mysql
,如下所示:
SELECT p.seller, p.purchase_date, p.report_no FROM purchases AS p UNION SELECT ps.seller, ps.purchase_date, ps.report_no FROM purchase_solds AS ps ORDER BY purchase_date DESC
那么我如何将其转换为laravel query-builder或laravel eloquent?
答案 0 :(得分:1)
你试过吗
$purchases = DB::table('purchases')
->select('seller', 'purchase_date', 'report_no');
$purchase_solds = DB::table('purchase_solds')
->select('seller', 'purchase_date', 'report_no')
->union($purchases)
->orderBy('purchase_date', 'desc')
->get();