我的情况类似。 我在发言中总结了我的问候,然后做了一个跳板的<代码>。 UNION ALLs for each row. 我的情况是,如果我有多份记录,那门单是不同的,那么我就走了前面,并补充说,在我的分组中,我的结果是确定的。 这也许不是这样做的最佳方式,而是为我的工作。
WITH query_a AS (
SELECT
fin_item.item_number || - || fin_item.item_descrip1 fin_item,
fin_ls.ls_number,
ls_sort.sortby_employeeid,
ls_sort.ncm_id,
ls_sort.created_at,
ls_sort.updated_at,
ls_sort.sort_qty,
ls_sort.initial_scan_time,
ls_sort.ncm_scan_time,
ls_sort.badge_scan_time,
ls_sort.computer_name,
ls_sort.number_of_ops,
ls_sort.ncm_item_scan_time,
sort_by.name sort_by,
tblncm.instructions,
tblncm.ncm_comments
FROM public.item AS fin_item
INNER JOIN public.ls AS fin_ls ON fin_item.item_id = fin_ls.ls_item_id
INNER JOIN stone.ls_sort ON fin_ls.ls_id = ls_sort.ls_id
INNER JOIN stone.vw_mssql_employees AS sort_by ON ls_sort.sortby_employeeid = sort_by.employeeid
INNER JOIN stone.tblncm ON ls_sort.ncm_id = tblncm.ncm_id
LEFT JOIN stone.equips AS mach_equips ON ls_sort.mach_equip_id = mach_equips.id
LEFT JOIN stone.equips AS mold_equips ON ls_sort.mold_equip_id = mold_equips.id
WHERE 1 = 1
AND fin_ls.ls_number ILIKE S143027526190 || %
)
SELECT *
FROM (
(SELECT fin_item my_column, fin_item::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
UNION ALL
(SELECT ls_number my_column, ls_number::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
UNION ALL
(SELECT sortby_employeeid my_column, sortby_employeeid::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
UNION ALL
(SELECT ncm_id my_column, ncm_id::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
UNION ALL
(SELECT created_at my_column, created_at::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
UNION ALL
(SELECT updated_at my_column, updated_at::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
UNION ALL
(SELECT sort_qty my_column, sort_qty::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
UNION ALL
(SELECT initial_scan_time my_column, initial_scan_time::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
UNION ALL
(SELECT ncm_scan_time my_column, ncm_scan_time::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
UNION ALL
(SELECT badge_scan_time my_column, badge_scan_time::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
UNION ALL
(SELECT computer_name my_column, computer_name::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
UNION ALL
(SELECT number_of_ops my_column, number_of_ops::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
UNION ALL
(SELECT ncm_item_scan_time my_column, ncm_item_scan_time::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
UNION ALL
(SELECT sort_by my_column, sort_by::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
UNION ALL
(SELECT instructions my_column, instructions::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
UNION ALL
(SELECT ncm_comments my_column, ncm_comments::TEXT my_value, ncm_id::TEXT my_ncm FROM query_a)
) as query_guy
ORDER BY my_ncm;