Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- SELECT
- DISTINCT(exg.nombre_grupo_examination)
- , (SELECT
- array_to_json(array_agg(row_to_json(d)))::jsonb
- FROM (
- SELECT
- ex.nombre_item_examination
- FROM
- public.examination_item ex
- WHERE ex.codigo_grupo_examination = exg.codigo_grupo_examination
- ) d ) items
- FROM
- public.examination_item exi
- LEFT JOIN public.examination_grupo exg ON exg.codigo_grupo_examination = exi.codigo_grupo_examination
- --******---
- SELECT
- array_to_json(array_agg(row_to_json(subq)))::text json_data
- FROM (
- SELECT
- DISTINCT(exg.nombre_grupo_examination)
- , (SELECT
- array_to_json(array_agg(row_to_json(d)))::jsonb
- FROM (
- SELECT
- ex.codigo_grupo_examination
- , ex.codigo_item_examination
- , ex.nombre_item_examination
- , CASE WHEN (TRIM(ex.unit_examination) = '') THEN null
- WHEN (TRIM(ex.unit_examination) IS NULL) THEN null
- ELSE CONCAT('[', ex.unit_examination, ']') END unit_examination
- FROM
- public.examination_item ex
- WHERE ex.codigo_grupo_examination = exg.codigo_grupo_examination
- ) d ) items
- FROM
- public.examination_item exi
- LEFT JOIN public.examination_grupo exg ON exg.codigo_grupo_examination = exi.codigo_grupo_examination
- ) subq
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement