vgrabovets
12/7/2016 - 4:40 PM

TV channels

TV channels

SELECT
  o.own
, al.cdn_obj_id
, v.title
, v.type
, v2.title
, v2.type
, db.name
, SUM(al.duration)
FROM
test.vg_tv_by al
    inner join (select 
    user_id
    from billing.orders where service_id in(19111, 19121)
    group by 1) u on u.user_id = al.user_id

    LEFT JOIN megogo2.video_live vl ON al.cdn_obj_id = vl.cdn_obj_id
    LEFT JOIN megogo2.video v2 ON vl.obj_id = v2.obj_id

    LEFT JOIN daily.own o ON al.cdn_obj_id = o.cdn_obj_id
    LEFT JOIN megogo2.video v ON o.own = v.obj_id
    LEFT JOIN megogo2.video_vod_country vvc ON v.obj_id = vvc.id_obj
    LEFT JOIN megogo2.biz_contracts bc ON bc.id = v.contract
    LEFT JOIN megogo2.biz_contracts bc1 ON bc1.id = bc.parent_contract
    LEFT JOIN megogo2.dict_biz db ON bc1.id_biz = db.biz_id
  GROUP BY al.cdn_obj_id
HAVING v2.type = 'TV'