[英]How do I write a select query in Laravel Eloquent with DISTINCT nested in COUNT?
我怎樣才能做到這一點是Eloquent:
select count(distinct(SID)) from history where `Date` < '2020-08-19'
你可以試試
History::distinct()->where('Date','<','2020-09-19')->count()
用於選擇特定列提供不同 function 內的列名
distinct('SID')
如果您的 Model 被命名為 History,我不知道您的 model 名稱是什么:)
$data = History::where('Date','<',''2020-09-19)->count();
在 model 一對多關系https://laravel.com/docs/7.x/eloquent-relationships
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.