我有Spot,DealItem和Daypart三种模型,每种模型都有自己的关系
class Spot extends Model
{
protected $table = 'avt_spot';
public $timestamps = false;
public function dealItem()
{
return $this->belongsTo('App\SkyDealitem', 'deal_core_service_id', 'core_service_id');
}
}
class SkyDealItem extends Model
{
protected $table = 'sky_deal_item';
public $timestamps = false;
public function daypart()
{
return $this->belongsTo('App\Daypart','daypart_code_id','id');
}
}
class Daypart extends Model
{
protected $table = 'avt_US_daypart';
public $timestamps = false;
public function deals()
{
return $this->hasMany('App\DealItem','daypart_code_id','id');
}
}
每个地点都会有一个名为pre_eval_tvr的列,既属于DealItem,也属于广告系列
每个DealItem都属于时段。
仅供参考-一个广告系列将有多个位置
现在我正在查询的查询是使用关系的按天明智pre_eval_tvr。
仅使用普通联接查询就可以获取,但是使用嵌套关系无法获取。
仅供参考-加入查询
select sum(avt_spot.pre_eval_tvr) as pre_eval_tvr, avt_US_daypart.*
from avt_spot
inner join sky_deal_item on avt_spot.deal_core_service_id = sky_deal_item.core_service_id
inner join avt_US_daypart on avt_US_daypart.id = sky_deal_item.daypart_code_id
where avt_spot.allocated_to_campaign = 4442
group by avt_US_daypart.id;