0
我有以下與正常工作的子查詢工作查詢我想transfrom以雄辯的,因爲我想堅持我的用戶模型的其他relaiont將原始查詢與子查詢侃侃而談
select * from (
select p.from, a.account_id, count(*) as num
from accounts as a
inner join accounts_prop as p on (a.account_id = p.account_id)
group by p.account_id
having num = 1) query
where year(query.von) = 2017
我已經有由(表accounts
)表示的用戶模型,並通過(properites
表)
User -> Property
關係所表示的屬性的模型是一對多
用戶
public function properties()
{
return $this->hasMany('App\Property', 'account_id', 'account_id');
}
物業
public function user()
{
return $this->belongsTo('App\User', 'account_id');
}
輸出應該歸還它有一個屬性和屬性當前日期相匹配的所有用戶。
在我的測試目的原始查詢我所用恆定的一年
工作,請發表您的表結構和發佈查詢您的預計產量。 –