我有一个看起来像附图的网格。网格的每个级别对应一个表。
研究表:代理,学习,ind_no,ind_sponsor,current_status
网站表: study,amtrackid,name,pi,dsa,status,irbappcr,ibc,obarac,ohrp,ib,prot,ic,global1572
实验室表: amtrackid,labid,name,cap,clia,lnv
调查员表: amtrackid,personid,name,cv,ml,fd,dot,hspt,pisort
如何生成循环通过表格的CSV文件,并提供类似于嵌套网格的输出?
-Agent Study IND_no ND_sponsor Current_Status------------------------------------------------------------- -9-cis-UAB30;UWI10-16-01R; 101064; DCP; Completed------------------------------------------------ ------------------Site PI ...----------------------------------------------------------------------------------------------------------------- -----University of Wisconsin Hospital and Clinics;Kolesar, Jill M, PharmD... ------------------------------------ ---------Lab CAP CLIA LNV------------------------------------------------------------------------------------------------ --------UAB University of Alabama Hospital Lab ...----------------------------------------------------------------- ---------Investigator CV FD----------------------------------------------------------------------------------------------- ---------Rahman (Davis), Zahra...
实验室和调查员处于同一水平。
更新
我尝试创建一个循环遍历它的函数,但查询会永远运行。我做错了什么?
CREATE OR REPLACE FUNCTION dw_regtrack.dash_parsing_quicklist(userName character)
RETURNS integer AS
$BODY$
DECLARE
superData RECORD;
studyData RECORD;
siteData RECORD;
siteData2 RECORD;
BEGIN
truncate table dw_regtrack.dash_output_quicklist;
for superData in (select agent, study, ind_no, sponsor, status, user_name as uname from dw_regtrack.qlstudies st left join dw_regtrack.user_studies us ON st.study=us.study_name)
loop
INSERT INTO dw_regtrack.dash_output_quicklist(agent,inform1,inform2,inform3,inform4,inform5)
(select agent, study, ind_no, sponsor, status,user_name from dw_regtrack.qlstudies st left join dw_regtrack.user_studies us ON st.study=us.study_name where superData.uname='gsamara');
--(select agent, study, ind_no, sponsor, status from dw_regtrack.qlstudies st left join dw_regtrack.user_studies us ON st.study=us.study_name where user_name='gsamara');
for studyData in (select study, amtrackid, name, pi, status, irbappcr, ohrp, ib, prot, ic, global1572, 1572, ibc, obarac, dsa from dw_regtrack.qlstudysites2)
loop
insert into dw_regtrack.dash_output_quicklist(agent, inform1, inform2, inform3, inform4, inform5, inform6, inform7, inform8, inform9, inform10, inform11,inform12,inform13,inform14,inform15)
(select '', study, amtrackid, name, pi, status, irbappcr, ohrp, ib, prot, ic, global1572, 1572, ibc, obarac, dsa from dw_regtrack.qlstudysites2 where studyData.study=superData.study);
for siteData in (select amtrackid, labid, name, cap, clia, lnv from dw_regtrack.qlstudysitelabs)
loop
insert into dw_regtrack.dash_output_quicklist(agent, inform1, inform2, inform3,inform4,inform5,inform6,inform7)
(select '','', amtrackid, labid, name, cap, clia, lnv from dw_regtrack.qlstudysitelabs where siteData.amtrackid=StudyData.amtrackid);
end loop;
for siteData2 in (select amtrackid, personid, name, cv, ml, fd, hspt, dot, pisort from dw_regtrack.qlstudysiteinvests2)
loop
insert into dw_regtrack.dash_output_quicklist(agent, inform1, inform2, inform3, inform4, inform5, inform6, inform7, inform8,inform9,inform10)
(select '', '', amtrackid, personid, name, cv, ml, fd, hspt, dot, pisort from dw_regtrack.qlstudysiteinvests2 where siteData2.amtrackid=studyData.amtrackid);
end loop;
end loop;
end loop;
Return 1;
END
$BODY$
LANGUAGE plpgsql VOLATILE
COST 100;
ALTER FUNCTION dw_regtrack.dash_parsing_quicklist(character)
OWNER TO postgres;