whatev

mail@pastecode.io avatar
unknown
sql
7 months ago
3.2 kB
1
Indexable
Never
SELECT
    formatDateTime(quit_time, '%d %b %y @ %H%p') quit_time, 
    formatDateTime(target_time, '%d %b %y @ %H%p') target_time,
    concat(toString(days_abs), 'd ', toString(hrs_rel), 'h ', toString(mins_rel), 'm') AS elapsed,
    hrs_abs AS elapsed_hrs,
    concat(toString(rem_days_abs), 'd ', toString(rem_hrs_rel), 'h ', toString(rem_mins_rel), 'm') AS remaining,
    target_tag,
    progress_bar,
    concat(
        toString(toInt64(f_percent_done)),
        '.',
        leftPad(toString(toInt64(f_percent_done * 100) % 100), 2, '0'),
        '%'
    ) percent_done,
    concat(
        toString(toInt64(100 - f_percent_done)),
        '.',
        leftPad(toString(toInt64((100 - f_percent_done) * 100) % 100), 2, '0'),
        '%'
    ) percent_left
FROM (
    SELECT 
        target_tag,
        target_time,
        curr_time,
        quit_time,
        dateDiff('second', quit_time, curr_time) AS seconds_abs,
        toInt64(seconds_abs / 86400) AS days_abs,
        toInt64(seconds_abs / 3600) AS hrs_abs,
        toInt64(seconds_abs / 60) AS mins_abs,
        hrs_abs - toInt64(days_abs * 24) AS hrs_rel,
        mins_abs - toInt64(hrs_abs * 60) AS mins_rel,
        greatest(dateDiff('second', curr_time, target_time), 0) AS rem_seconds_abs,
        toInt64(rem_seconds_abs / 86400) AS rem_days_abs,
        toInt64(rem_seconds_abs / 3600) AS rem_hrs_abs,
        toInt64(rem_seconds_abs / 60) AS rem_mins_abs,
        rem_hrs_abs - toInt64(rem_days_abs * 24) AS rem_hrs_rel,
        rem_mins_abs - toInt64(rem_hrs_abs * 60) AS rem_mins_rel,
        progress_bar,
        f_percent_done
    FROM (
        SELECT
            quit_time,
            curr_time,
            x.1 AS target_tag,
            x.2 AS target_time,
            dateDiff('second', quit_time, curr_time) AS curr_val,
            dateDiff('second', quit_time, x.2) AS max_val,
            bar(curr_val, 0, max_val, 50) AS progress_bar,
            least((curr_val / max_val * 100), 100) as f_percent_done
        FROM (
            SELECT
                'Asia/Singapore' AS tz,
                toDateTime('2024-02-07 10:00:00', tz) AS quit_time,
                toDateTime(now(), tz) AS curr_time,
                arrayJoin(array(
                    ('4 weeks', addWeeks(quit_time, 4)),
                    ('1 month', addMonths(quit_time, 1)),
                    ('5 weeks', addWeeks(quit_time, 5)),
                    ('6 weeks', addWeeks(quit_time, 6)),
                    ('666 hrs', addHours(quit_time, 666)),
                    ('700 hrs', addHours(quit_time, 700)),
                    ('777 hrs', addHours(quit_time, 777)),
                    ('800 hrs', addHours(quit_time, 800)),
                    ('888 hrs', addHours(quit_time, 888)),
                    ('900 hrs', addHours(quit_time, 900)),
                    ('1000 hrs', addHours(quit_time, 1000)),
                    ('1024 hrs', addHours(quit_time, 1024)),
                    ('2 months', addMonths(quit_time, 2)),
                    ('3 months', addMonths(quit_time, 3)),
                    ('6 months', addMonths(quit_time, 6)),
                    ('year', addMonths(quit_time, 12))
                )) AS x
        )
    )
) ORDER BY f_percent_done DESC

Leave a Comment