日期:2014-05-16  浏览次数:20417 次

DB2中 同一个表中多条数据组合成一条数据 (一条SQL实现)


 SELECT
 (
  SELECT PERSONNAME  FROM
(
select "PERSONNAME",  "GENDER", 
      "BIRTHDAY",   "NATIONALITY", "PASSPORT_NUMBER"  from (    select   ROWNUMBER() OVER() as  ROWID ,"PERSONNAME", "GENDER", 
      "BIRTHDAY",   "NATIONALITY", "PASSPORT_NUMBER" 
  from  T_GA_PERSONLIST  where  GROUPGUID= '4a43c92c-9db6-41d7-b23b-ba8180b04adf'
ORDER BY RECORD_GUID ) as a  where a.ROWID=1
) AS B
) AS PERSONNAME1
, (
 SELECT GENDER  FROM
(
select "PERSONNAME",  "GENDER", 
      "BIRTHDAY",   "NATIONALITY", "PASSPORT_NUMBER"  from (    select   ROWNUMBER() OVER() as  ROWID ,"PERSONNAME",  "GENDER", 
      "BIRTHDAY",   "NATIONALITY", "PASSPORT_NUMBER" 
  from  T_GA_PERSONLIST  where  GROUPGUID= '4a43c92c-9db6-41d7-b23b-ba8180b04adf'
ORDER BY RECORD_GUID ) as a  where a.ROWID=1
) AS B
) AS GENDER1
, (
 SELECT BIRTHDAY  FROM
(
select "PERSONNAME",  "GENDER", 
      "BIRTHDAY",   "NATIONALITY", "PASSPORT_NUMBER"  from (    select   ROWNUMBER() OVER() as  ROWID ,"PERSONNAME",  "GENDER", 
      "BIRTHDAY",   "NATIONALITY", "PASSPORT_NUMBER" 
  from  T_GA_PERSONLIST  where  GROUPGUID= '4a43c92c-9db6-41d7-b23b-ba8180b04adf'
ORDER BY RECORD_GUID ) as a  where a.ROWID=1
) AS B
) AS BIRTHDAY1 
, (
 SELECT NATIONALITY  FROM
(
select "PERSONNAME",  "GENDER", 
      "BIRTHDAY",   "NATIONALITY", "PASSPORT_NUMBER"  from (    select   ROWNUMBER() OVER() as  ROWID ,"PERSONNAME",  "GENDER", 
      "BIRTHDAY",   "NATIONALITY", "PASSPORT_NUMBER" 
  from  T_GA_PERSONLIST  where  GROUPGUID= '4a43c92c-9db6-41d7-b23b-ba8180b04adf'
ORDER BY RECORD_GUID ) as a  where a.ROWID=1
) AS B
) AS NATIONALITY1 
, (
 SELECT PASSPORT_NUMBER  FROM
(
select "PERSONNAME",  "GENDER", 
      "BIRTHDAY",   "NATIONALITY", "PASSPORT_NUMBER"  from (    select   ROWNUMBER() OVER() as  ROWID ,"PERSONNAME&qu