USEGEAR

导航

PG把多条记录合并成字符串,用逗号分隔

select array_to_string(
  array(
select quote_literal("HD_Code") from "public"."Hosp_Dept" where "HD_Code" in ('103001','103002','103') and "HD_SFMJ" is True), ';'
) as strs;
--------quote_literal
'103002';'103001'4

select array_to_string(
  array(select quote_ident("HD_Code") from "public"."Hosp_Dept" where "HD_Code" in ('103001','103002','103') and  "HD_SFMJ" is True), ','
) as strs;
--------quote_ident
"103002","103001"

 

 

posted on 2023-02-18 18:00  USEGEAR  阅读(330)  评论(0编辑  收藏  举报