Skip to content

Instantly share code, notes, and snippets.

@tfgrahame
Created August 16, 2019 14:12
Show Gist options
  • Save tfgrahame/8f05c653f57afd29d9e518a54b788d34 to your computer and use it in GitHub Desktop.
Save tfgrahame/8f05c653f57afd29d9e518a54b788d34 to your computer and use it in GitHub Desktop.
SELECT
s.service_id, COUNT(s.service_id)
FROM
service s
LEFT JOIN
(SELECT
s.service_id
FROM
service s
JOIN broadcast b ON s.service_id = b.service_id
WHERE
b.planned_start_time IS NOT NULL
AND DATE(b.created) > '2017-12-05'
AND YEAR(b.published_time) > '2017') AS planned ON s.service_id = planned.service_id
JOIN
entity e ON e.pid = s.pid
AND e.partner_pid = 's0000001'
WHERE
s.type = 'TV'
GROUP BY s.service_id
ORDER BY COUNT(s.service_id) DESC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment