By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0.
version() |
---|
8.0.27 |
case_id | cat | birth | c_type | c_t |
---|---|---|---|---|
20033738 | CASE_OWNER | 1996-04-08 | null | PAIR_NO_CHILD |
20033738 | WIFE | 1995-08-22 | null | PAIR_NO_CHILD |
20033831 | CASE_OWNER | 1975-03-05 | null | SINGLE_WITH_CHILD |
20033831 | CHILD | 2013-10-25 | null | SINGLE_WITH_CHILD |
20033831 | CHILD | 2010-05-20 | null | SINGLE_WITH_CHILD |
20033831 | CHILD | 2006-03-25 | null | SINGLE_WITH_CHILD |
20033831 | CHILD | 2005-03-19 | null | SINGLE_WITH_CHILD |
20039301 | CASE_OWNER | 1999-07-27 | null | PAIR_WITH_CHILD |
20039301 | WIFE | 2001-07-05 | null | PAIR_WITH_CHILD |
20039301 | CHILD | 2018-10-22 | null | PAIR_WITH_CHILD |
20039334 | CASE_OWNER | 1994-03-10 | null | SINGLE_PERSON |
30033333 | CASE_OWNER | 1980-01-01 | null | SINGLE_WITH_CHILD |
30033333 | CHILD | 2012-09-01 | null | SINGLE_WITH_CHILD |
30044444 | CASE_OWNER | 2015-08-10 | null | UNKNOWN |
30055555 | CASE_OWNER | 1970-02-10 | null | OTHER |
30055555 | WIFE | 1972-07-05 | null | OTHER |
30055555 | CHILD | 1997-05-19 | null | OTHER |
30055555 | CHILD | 1995-11-22 | null | OTHER |
30066666 | CASE_OWNER | 1970-02-10 | null | MULTIPLE |
30066666 | CHILD | 1994-05-19 | null | MULTIPLE |
30066666 | CHILD | 1992-11-22 | null | MULTIPLE |
30066666 | CHILD | 1989-07-05 | null | MULTIPLE |
case_id | cat | birth | c_t |
---|---|---|---|
20033738 | CASE_OWNER | 1996-04-08 | PAIR_NO_CHILD |
20033738 | WIFE | 1995-08-22 | PAIR_NO_CHILD |
20033831 | CASE_OWNER | 1975-03-05 | SINGLE_WITH_CHILD |
20033831 | CHILD | 2013-10-25 | SINGLE_WITH_CHILD |
20033831 | CHILD | 2010-05-20 | SINGLE_WITH_CHILD |
20033831 | CHILD | 2006-03-25 | SINGLE_WITH_CHILD |
20033831 | CHILD | 2005-03-19 | SINGLE_WITH_CHILD |
20039301 | CASE_OWNER | 1999-07-27 | PAIR_WITH_CHILD |
20039301 | WIFE | 2001-07-05 | PAIR_WITH_CHILD |
20039301 | CHILD | 2018-10-22 | PAIR_WITH_CHILD |
20039334 | CASE_OWNER | 1994-03-10 | SINGLE PERSON |
30033333 | CASE_OWNER | 1980-01-01 | SINGLE_WITH_CHILD |
30033333 | CHILD | 2012-09-01 | SINGLE_WITH_CHILD |
30044444 | CASE_OWNER | 2015-08-10 | UNKNOWN |
30055555 | CASE_OWNER | 1970-02-10 | OTHER |
30055555 | WIFE | 1972-07-05 | OTHER |
30055555 | CHILD | 1997-05-19 | OTHER |
30055555 | CHILD | 1995-11-22 | OTHER |
30066666 | CASE_OWNER | 1970-02-10 | MULTIPLE |
30066666 | CHILD | 1994-05-19 | MULTIPLE |
30066666 | CHILD | 1992-11-22 | MULTIPLE |
30066666 | CHILD | 1989-07-05 | MULTIPLE |
EXPLAIN |
---|
-> Sort: cas.case_id, `(case when (cas.cat = 'CASE_OWNER') then 1 when (cas.cat = 'WIFE') then 2 when (cas.cat = 'CHILD') then 3 end)`, cas.birth DESC (actual time=1.659..1.668 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.001..0.006 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=1.629..1.635 rows=22 loops=1) -> Window aggregate with buffering: min(```((to_days(now()) - to_days(cas.birth)) / 365.25)```) OVER (PARTITION BY cas.case_id ) (actual time=1.374..1.577 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.001..0.007 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=1.328..1.337 rows=22 loops=1) -> Window aggregate with buffering: sum(```(case when (cas.cat = 'WIFE') then 1 else 0 end)```) OVER (PARTITION BY cas.case_id ) (actual time=1.138..1.292 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.001..0.007 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=1.101..1.110 rows=22 loops=1) -> Window aggregate with buffering: count(cas.case_id) OVER (PARTITION BY cas.case_id ) (actual time=0.923..1.075 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.000..0.006 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=0.909..0.916 rows=22 loops=1) -> Window aggregate with buffering: min(```((to_days(now()) - to_days(cas.birth)) / 365.25)```) OVER (PARTITION BY cas.case_id ) (actual time=0.784..0.898 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.000..0.005 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=0.762..0.769 rows=22 loops=1) -> Window aggregate with buffering: sum(```(case when (cas.cat = 'WIFE') then 1 else 0 end)```) OVER (PARTITION BY cas.case_id ) (actual time=0.647..0.751 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.000..0.005 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=0.633..0.640 rows=22 loops=1) -> Window aggregate with buffering: count(cas.case_id) OVER (PARTITION BY cas.case_id ) (actual time=0.524..0.624 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.001..0.005 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=0.511..0.518 rows=22 loops=1) -> Window aggregate with buffering: sum(```(case when (cas.cat = 'WIFE') then 1 else 0 end)```) OVER (PARTITION BY cas.case_id ) (actual time=0.383..0.499 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.000..0.005 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=0.370..0.377 rows=22 loops=1) -> Window aggregate with buffering: count(cas.case_id) OVER (PARTITION BY cas.case_id ) (actual time=0.273..0.361 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.001..0.005 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=0.261..0.266 rows=22 loops=1) -> Window aggregate with buffering: count(cas.case_id) OVER (PARTITION BY cas.case_id ) (actual time=0.085..0.249 rows=22 loops=1) -> Sort: cas.case_id (cost=2.45 rows=22) (actual time=0.046..0.051 rows=22 loops=1) -> Table scan on cas (cost=2.45 rows=22) (actual time=0.012..0.031 rows=22 loops=1) |
EXPLAIN |
---|
-> Table scan on s (cost=0.13..2.77 rows=22) (actual time=0.000..0.003 rows=22 loops=1) -> Materialize (cost=4.78..7.43 rows=22) (actual time=4.470..4.473 rows=22 loops=1) -> Sort: c1.case_id, (case when (c1.cat = 'CASE_OWNER') then 1 when (c1.cat = 'WIFE') then 2 when (c1.cat = 'CHILD') then 3 end), c1.birth DESC (cost=2.45 rows=22) (actual time=0.110..0.134 rows=22 loops=1) -> Table scan on c1 (cost=2.45 rows=22) (actual time=0.012..0.080 rows=22 loops=1) -> Select #3 (subquery in projection; dependent) -> Table scan on <temporary> (actual time=0.000..0.000 rows=1 loops=22) -> Aggregate using temporary table (actual time=0.045..0.046 rows=1 loops=22) -> Filter: (c2.case_id = c1.case_id) (cost=0.47 rows=2) (actual time=0.013..0.026 rows=3 loops=22) -> Table scan on c2 (cost=0.47 rows=22) (actual time=0.006..0.023 rows=22 loops=22) -> Select #4 (subquery in projection; dependent) -> Table scan on <temporary> (actual time=0.000..0.000 rows=1 loops=22) -> Aggregate using temporary table (actual time=0.049..0.049 rows=1 loops=22) -> Filter: (c3.case_id = c1.case_id) (cost=0.47 rows=2) (actual time=0.014..0.027 rows=3 loops=22) -> Table scan on c3 (cost=0.47 rows=22) (actual time=0.007..0.024 rows=22 loops=22) -> Select #5 (subquery in projection; dependent) -> Table scan on <temporary> (actual time=0.000..0.000 rows=1 loops=22) -> Aggregate using temporary table (actual time=0.056..0.056 rows=1 loops=22) -> Filter: (c4.case_id = c1.case_id) (cost=0.47 rows=2) (actual time=0.013..0.026 rows=3 loops=22) -> Table scan on c4 (cost=0.47 rows=22) (actual time=0.006..0.023 rows=22 loops=22) |
EXPLAIN |
---|
-> Window aggregate with buffering: min(```((to_days(now()) - to_days(cas.birth)) / 365.25)```) OVER (PARTITION BY cas.case_id ) (actual time=1.420..1.596 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.001..0.006 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=1.378..1.386 rows=22 loops=1) -> Window aggregate with buffering: sum(```(case when (cas.cat = 'WIFE') then 1 else 0 end)```) OVER (PARTITION BY cas.case_id ) (actual time=1.199..1.339 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.001..0.007 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=1.141..1.150 rows=22 loops=1) -> Window aggregate with buffering: count(cas.case_id) OVER (PARTITION BY cas.case_id ) (actual time=1.008..1.126 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.001..0.006 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=0.981..0.988 rows=22 loops=1) -> Window aggregate with buffering: min(```((to_days(now()) - to_days(cas.birth)) / 365.25)```) OVER (PARTITION BY cas.case_id ) (actual time=0.851..0.965 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.001..0.006 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=0.827..0.835 rows=22 loops=1) -> Window aggregate with buffering: sum(```(case when (cas.cat = 'WIFE') then 1 else 0 end)```) OVER (PARTITION BY cas.case_id ) (actual time=0.708..0.812 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.000..0.005 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=0.687..0.694 rows=22 loops=1) -> Window aggregate with buffering: count(cas.case_id) OVER (PARTITION BY cas.case_id ) (actual time=0.573..0.672 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.001..0.005 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=0.551..0.559 rows=22 loops=1) -> Window aggregate with buffering: sum(```(case when (cas.cat = 'WIFE') then 1 else 0 end)```) OVER (PARTITION BY cas.case_id ) (actual time=0.444..0.538 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.001..0.005 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=0.422..0.429 rows=22 loops=1) -> Window aggregate with buffering: count(cas.case_id) OVER (PARTITION BY cas.case_id ) (actual time=0.312..0.401 rows=22 loops=1) -> Table scan on <temporary> (cost=2.50..2.50 rows=0) (actual time=0.001..0.005 rows=22 loops=1) -> Temporary table (cost=2.50..2.50 rows=0) (actual time=0.286..0.293 rows=22 loops=1) -> Window aggregate with buffering: count(cas.case_id) OVER (PARTITION BY cas.case_id ) (actual time=0.080..0.274 rows=22 loops=1) -> Sort: cas.case_id (cost=2.45 rows=22) (actual time=0.045..0.051 rows=22 loops=1) -> Table scan on cas (cost=2.45 rows=22) (actual time=0.012..0.030 rows=22 loops=1) |
EXPLAIN |
---|
-> Table scan on s (cost=0.13..2.77 rows=22) (actual time=0.001..0.003 rows=22 loops=1) -> Materialize (cost=4.78..7.43 rows=22) (actual time=4.827..4.831 rows=22 loops=1) -> Table scan on c1 (cost=2.45 rows=22) (actual time=0.011..0.044 rows=22 loops=1) -> Select #3 (subquery in projection; dependent) -> Table scan on <temporary> (actual time=0.000..0.000 rows=1 loops=22) -> Aggregate using temporary table (actual time=0.045..0.045 rows=1 loops=22) -> Filter: (c2.case_id = c1.case_id) (cost=0.47 rows=2) (actual time=0.013..0.025 rows=3 loops=22) -> Table scan on c2 (cost=0.47 rows=22) (actual time=0.006..0.022 rows=22 loops=22) -> Select #4 (subquery in projection; dependent) -> Table scan on <temporary> (actual time=0.000..0.000 rows=1 loops=22) -> Aggregate using temporary table (actual time=0.050..0.050 rows=1 loops=22) -> Filter: (c3.case_id = c1.case_id) (cost=0.47 rows=2) (actual time=0.013..0.027 rows=3 loops=22) -> Table scan on c3 (cost=0.47 rows=22) (actual time=0.006..0.023 rows=22 loops=22) -> Select #5 (subquery in projection; dependent) -> Table scan on <temporary> (actual time=0.000..0.000 rows=1 loops=22) -> Aggregate using temporary table (actual time=0.075..0.075 rows=1 loops=22) -> Filter: (c4.case_id = c1.case_id) (cost=0.47 rows=2) (actual time=0.033..0.046 rows=3 loops=22) -> Table scan on c4 (cost=0.47 rows=22) (actual time=0.025..0.043 rows=22 loops=22) |
case_id | cat | birth | c_type | c_t |
---|---|---|---|---|
20033738 | CASE_OWNER | 1996-04-08 | null | PAIR_NO_CHILD |
20033738 | WIFE | 1995-08-22 | null | PAIR_NO_CHILD |
20033831 | CASE_OWNER | 1975-03-05 | null | YYYY |
20033831 | CHILD | 2013-10-25 | null | YYYY |
20033831 | CHILD | 2010-05-20 | null | YYYY |
20033831 | CHILD | 2006-03-25 | null | YYYY |
20033831 | CHILD | 2005-03-19 | null | YYYY |
20039301 | CASE_OWNER | 1999-07-27 | null | YYYY |
20039301 | WIFE | 2001-07-05 | null | YYYY |
20039301 | CHILD | 2018-10-22 | null | YYYY |
20039334 | CASE_OWNER | 1994-03-10 | null | YYYY |
30033333 | CASE_OWNER | 1980-01-01 | null | null |
30033333 | CHILD | 2012-09-01 | null | null |
30044444 | CASE_OWNER | 2015-08-10 | null | YYYY |
30055555 | CASE_OWNER | 1970-02-10 | null | YYYY |
30055555 | WIFE | 1972-07-05 | null | YYYY |
30055555 | CHILD | 1997-05-19 | null | YYYY |
30055555 | CHILD | 1995-11-22 | null | YYYY |
30066666 | CASE_OWNER | 1970-02-10 | null | YYYY |
30066666 | CHILD | 1994-05-19 | null | YYYY |
30066666 | CHILD | 1992-11-22 | null | YYYY |
30066666 | CHILD | 1989-07-05 | null | YYYY |