forked from rho_n/hpr_generator
Using even more complex CTE query for testing
This commit is contained in:
parent
3ccd6101ee
commit
dab80f1772
@ -1,29 +1,31 @@
|
||||
<!--% query_next_available_episode = '
|
||||
WITH next_id AS (
|
||||
SELECT id, id + 1 AS id_next, date as last_date
|
||||
FROM eps
|
||||
WHERE eps.date > date(\'now\')
|
||||
WITH RECURSIVE
|
||||
min_id AS (
|
||||
SELECT max(id) AS start_id FROM eps WHERE date <= date(\'now\')
|
||||
),
|
||||
free_slot AS (
|
||||
max_id 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
|
||||
last_date AS prev_date,
|
||||
CASE
|
||||
WHEN strftime(\'%w\',last_date) = \'5\'
|
||||
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
|
||||
cnt.x AS id
|
||||
FROM cnt
|
||||
LEFT JOIN eps e ON cnt.x = e.id
|
||||
WHERE e.id IS NULL
|
||||
)
|
||||
SELECT
|
||||
empty_slot AS next_id,
|
||||
DATE (prev_date, date_offset) AS next_date,
|
||||
printf(\'%i\',abs(julianday(DATE (prev_date, date_offset)) - julianday(\'now\') + 1)) AS delta_days
|
||||
FROM free_slot
|
||||
fe.id as empty_slot,
|
||||
(SELECT date(eps.date,\'+1 day\') from eps where id = fe.id-1) as slot_date,
|
||||
printf(\'%i\',abs(julianday((SELECT date(eps.date,\'+1 day\') from eps where id = fe.id-1)) - julianday(\'now\') + 1)) AS delta_days
|
||||
FROM first_empty AS fe
|
||||
LEFT JOIN eps e ON fe.id = e.id
|
||||
LIMIT 1
|
||||
'
|
||||
%-->
|
||||
<!--% query_latest_episodes = '
|
||||
|
Loading…
Reference in New Issue
Block a user