clear markdown compare help donate or buy diddy dollings comments/suggestions/bugs a leap of faith? bible365
clear markdown donate comments/suggestions/bugs a leap of faith? bible365 diddy dollings
By using db<>fiddle, you agree to license everything you submit by Creative Commons CC0. 582716 fiddles created (13315 in the last week).

CREATE TABLE raw ( "ID" serial primary key, "Data" json ); INSERT INTO raw ("Data") VALUES ('[1,2,3,5,6,7,9,10]'::json); CREATE TABLE features ( "ID" int, "Features" json ); INSERT INTO features ("ID", "Features") VALUES (1, '{"Start" : 1, "End": 5}');
1 rows affected
1 rows affected
 hidden batch(es)


SELECT r."ID", MAX(t.elem::int) MaxElem FROM raw r JOIN features f ON f."ID" = r."ID" JOIN LATERAL json_array_elements_text(r."Data") WITH ORDINALITY AS t(elem, n) ON TRUE WHERE n >= (f."Features"->>'Start')::int + 1 AND n <= (f."Features"->>'End')::int + 1 GROUP BY r."ID";
ID maxelem
1 7
 hidden batch(es)