Compare commits
No commits in common. "c8135d811d8930e06f32cb7e0d5a8f46d507b25c" and "3ccd6101ee5a9f351d9de8ab5a89077199897446" have entirely different histories.
c8135d811d
...
3ccd6101ee
@ -1,31 +1,29 @@
|
|||||||
<!--% query_next_available_episode = '
|
<!--% query_next_available_episode = '
|
||||||
WITH RECURSIVE
|
WITH next_id AS (
|
||||||
min_id AS (
|
SELECT id, id + 1 AS id_next, date as last_date
|
||||||
SELECT max(id) AS start_id FROM eps WHERE date <= NOW()
|
FROM eps
|
||||||
|
WHERE eps.date > NOW()
|
||||||
),
|
),
|
||||||
max_id AS (
|
free_slot AS (
|
||||||
SELECT max(id) AS end_id FROM eps
|
|
||||||
),
|
|
||||||
cnt(x) AS (
|
|
||||||
SELECT start_id from min_id
|
|
||||||
UNION ALL
|
|
||||||
SELECT x+1 FROM cnt
|
|
||||||
WHERE x+1 <= (SELECT end_id FROM max_id)
|
|
||||||
),
|
|
||||||
first_empty AS (
|
|
||||||
SELECT
|
SELECT
|
||||||
cnt.x AS id
|
last_date AS prev_date,
|
||||||
FROM cnt
|
CASE
|
||||||
LEFT JOIN eps e ON cnt.x = e.id
|
WHEN DAYOFWEEK(last_date) = 6
|
||||||
WHERE e.id IS NULL
|
THEN 3
|
||||||
|
ELSE 1
|
||||||
|
END AS date_offset,
|
||||||
|
next_id.id_next AS empty_slot
|
||||||
|
FROM next_id
|
||||||
|
LEFT JOIN eps ON next_id.id_next = eps.id
|
||||||
|
WHERE eps.id IS NULL
|
||||||
|
ORDER BY next_id.id
|
||||||
|
LIMIT 1
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
fe.id as next_id,
|
empty_slot AS next_id,
|
||||||
(SELECT DATE(ADDDATE(e2.date,1)) from eps e2 where e2.id = fe.id-1) as next_date,
|
ADDDATE(prev_date,date_offset) AS next_date,
|
||||||
DATEDIFF((SELECT ADDDATE(e3.date,1) from eps e3 where e3.id = fe.id-1),now()) AS delta_days
|
DATEDIFF(ADDDATE(prev_date,date_offset),NOW()) AS delta_days
|
||||||
FROM first_empty AS fe
|
FROM free_slot
|
||||||
LEFT JOIN eps e1 ON fe.id = e1.id
|
|
||||||
LIMIT 1
|
|
||||||
'
|
'
|
||||||
%-->
|
%-->
|
||||||
<!--% query_latest_episodes = '
|
<!--% query_latest_episodes = '
|
||||||
|
@ -1,31 +1,29 @@
|
|||||||
<!--% query_next_available_episode = '
|
<!--% query_next_available_episode = '
|
||||||
WITH RECURSIVE
|
WITH next_id AS (
|
||||||
min_id AS (
|
SELECT id, id + 1 AS id_next, date as last_date
|
||||||
SELECT max(id) AS start_id FROM eps WHERE date <= date(\'now\')
|
FROM eps
|
||||||
|
WHERE eps.date > date(\'now\')
|
||||||
),
|
),
|
||||||
max_id AS (
|
free_slot AS (
|
||||||
SELECT max(id) AS end_id FROM eps
|
|
||||||
),
|
|
||||||
cnt(x) AS (
|
|
||||||
SELECT start_id from min_id
|
|
||||||
UNION ALL
|
|
||||||
SELECT x+1 FROM cnt
|
|
||||||
WHERE x+1 <= (SELECT end_id FROM max_id)
|
|
||||||
),
|
|
||||||
first_empty AS (
|
|
||||||
SELECT
|
SELECT
|
||||||
cnt.x AS id
|
last_date AS prev_date,
|
||||||
FROM cnt
|
CASE
|
||||||
LEFT JOIN eps e ON cnt.x = e.id
|
WHEN strftime(\'%w\',last_date) = \'5\'
|
||||||
WHERE e.id IS NULL
|
THEN \'+3 days\'
|
||||||
|
ELSE \'+1 days\'
|
||||||
|
END AS date_offset,
|
||||||
|
next_id.id_next AS empty_slot
|
||||||
|
FROM next_id
|
||||||
|
LEFT JOIN eps ON next_id.id_next = eps.id
|
||||||
|
WHERE eps.id IS NULL
|
||||||
|
ORDER BY next_id.id
|
||||||
|
LIMIT 1
|
||||||
)
|
)
|
||||||
SELECT
|
SELECT
|
||||||
fe.id as next_id,
|
empty_slot AS next_id,
|
||||||
(SELECT date(eps.date,\'+1 day\') from eps where id = fe.id-1) as next_date,
|
DATE (prev_date, date_offset) AS next_date,
|
||||||
printf(\'%i\',abs(julianday((SELECT date(eps.date,\'+1 day\') from eps where id = fe.id-1)) - julianday(\'now\') + 1)) AS delta_days
|
printf(\'%i\',abs(julianday(DATE (prev_date, date_offset)) - julianday(\'now\') + 1)) AS delta_days
|
||||||
FROM first_empty AS fe
|
FROM free_slot
|
||||||
LEFT JOIN eps e ON fe.id = e.id
|
|
||||||
LIMIT 1
|
|
||||||
'
|
'
|
||||||
%-->
|
%-->
|
||||||
<!--% query_latest_episodes = '
|
<!--% query_latest_episodes = '
|
||||||
|
Reference in New Issue
Block a user