通过concat内部联接查询在报表中显示一行

时间:2017-08-21 08:09:09

标签: oracle

SELECT t.TRAINER_ID,
              t.LAST_NAME,
       t.ID_NUM,
            t.language,
       --t.Service,
       -- t.Unit,
       --t.Rate,
       (TSI.service || ' - ' || TSI.unit || ' - ' || TSI.rate) INFO  -- This is the join table I want one row to display in the report

  FROM LMS$TRAINERS T
  inner   join Trainer_service_info TSI
  on T.trainer_id = TSI.trainer_id
 WHERE COMPANY_ID = :P0_COMPANY_ID AND status = 'A'

以上代码显示以下结果

Trainer_id  Name    ID              Lanuage             INFO             
1000018582  Twynam  5304025007080   Afrikaans:English   8 - 1 - 150     
1000018582  Twynam  5304025007080   Afrikaans:English   7 - 2 - 700     

我希望它显示

Trainer_id  Name    ID              Lanuage             INFO             
1000018582  Twynam  5304025007080   Afrikaans:English   8 - 1 - 150 - 7 - 2 - 700   

1 个答案:

答案 0 :(得分:0)

with listagg

SELECT t.TRAINER_ID,
          t.LAST_NAME,
   t.ID_NUM,
        t.language,
   --t.Service,
   -- t.Unit,
   --t.Rate,
   TSI.INFO  -- This is the join table I want one row to display in the report
  FROM LMS$TRAINERS T
  inner   join (select trainer_id,listagg(service || ' - ' || unit || ' - ' || rate,' - ') within group (order by trainer_id) as info from Trainer_service_info group by trainer_id) TSI
  on T.trainer_id = TSI.trainer_id;