Add many queries for finding gaps between appearances

This commit is contained in:
gg1234 2024-04-13 08:05:04 -07:00
parent 0ba825e945
commit 5ba57b2fad
1 changed files with 55 additions and 2 deletions

View File

@ -216,14 +216,67 @@ HAVING c > 1
-- Caster's Last Appearance
SELECT c.n AS name,
MAX(s.jst) AS last_appearance,
JULIANDAY(DATETIME('now', '+09:00')) - JULIANDAY(MAX(s.jst)) AS days_since
JULIANDAY(DATETIME('now', '+09:00')) - JULIANDAY(MAX(s.jst)) AS days_since,
MAX(s.jst) AS last_appearance
FROM schedule s
JOIN caster c ON c.id = s.caster_id
WHERE s.jst < REPLACE(DATETIME('now', '+09:00'), ' ', 'T')
GROUP BY c.n
ORDER BY last_appearance DESC;
-- Max days between caster appearances for all casters
SELECT name, MAX(diff) as days, prev, jst
FROM (SELECT c.n AS name,
JULIANDAY(s.jst) - LAG(JULIANDAY(s.jst), 1, 0) OVER (ORDER BY s.caster_id, s.jst) AS diff,
s.jst AS jst,
LAG(s.jst, 1, 0) OVER (ORDER BY s.caster_id, s.jst) AS prev
FROM schedule s
JOIN caster c ON c.id = s.caster_id
WHERE s.segment_id != 8
ORDER BY s.caster_id, s.jst)
WHERE prev != 0
GROUP BY name
ORDER BY days DESC;
-- Max days between caster appearances
SELECT name, MAX(diff) AS days, prev, jst FROM (
SELECT c.n AS name,
JULIANDAY(s.jst) - LAG(JULIANDAY(s.jst), 1, 0) OVER (ORDER BY s.jst) AS diff,
s.jst AS jst,
LAG(s.jst, 1, 0) OVER (ORDER BY s.jst) AS prev
FROM schedule s
JOIN caster c ON c.id = s.caster_id
WHERE c.n = "&caster"
AND s.segment_id != 8
ORDER BY s.jst) gaps
WHERE prev != 0;
-- Top 3 days between caster appearances
SELECT name, diff AS days, prev, jst FROM (
SELECT c.n AS name,
JULIANDAY(s.jst) - LAG(JULIANDAY(s.jst), 1, 0) OVER (ORDER BY s.jst) AS diff,
s.jst AS jst,
LAG(s.jst, 1, 0) OVER (ORDER BY s.jst) AS prev
FROM schedule s
JOIN caster c ON c.id = s.caster_id
WHERE c.n = "&caster"
AND s.segment_id != 8
ORDER BY s.jst) gaps
WHERE prev != 0
ORDER BY gaps.diff DESC
LIMIT 3;
-- Days between caster appearances
SELECT c.n AS name,
JULIANDAY(s.jst) - LAG(JULIANDAY(s.jst), 1, 0) OVER (ORDER BY s.jst) AS diff,
s.jst AS jst,
LAG(s.jst, 1, 0) OVER (ORDER BY s.jst) AS prev
FROM schedule s
JOIN caster c ON c.id = s.caster_id
WHERE c.n = "&caster"
AND s.segment_id != 8
ORDER BY s.jst;
-- MANUAL FIXES
-- copy matsu's cancelled coffee time to cancellation table