1

異なる行で出力する 1 対多の関係を 1 つの行に統合したいと考えています。

(select rate_value1 
      FROM xgenca_enquiry_event 
       INNER JOIN  xgenca_enquiry_iso_code_translation 
             ON 
       xgenca_enquiry_event_rate.rate_code_id 
           = xgenca_enquiry_iso_code_translation.id  
       where xgenca_enquiry_event_rate.event_id = xgenca_enquiry_event.id 
              and ISO_code = 'PDIV') as PDIVrate, 
(select rate_value1 
       FROM xgenca_enquiry_event 
        INNER JOIN xgenca_enquiry_iso_code_translation 
              ON 
         xgenca_enquiry_event_rate.rate_code_id 
           = xgenca_enquiry_iso_code_translation.id  
        where xgenca_enquiry_event_rate.event_id = xgenca_enquiry_event.id 
              and ISO_code = 'TAXR') as TAXrate

PDIVrate    TAXrate
NULL        10.0000000
0.0059120   NULL

結果を 1 行で表示したい。どんな助けでも大歓迎です。ありがとう。

4

2 に答える 2

2

集計関数を使用してこれを実行できます。

select 
  max(case when ISO_code = 'PDIV' then rate_value1 end) PDIVRate,
  max(case when ISO_code = 'TAXR' then rate_value1 end) TAXRate
FROM xgenca_enquiry_event_rate r 
INNER JOIN  xgenca_enquiry_iso_code_translation t
  ON r.rate_code_id = t.id  
INNER JOIN xgenca_enquiry_event e
  ON r.event_id = e.id 

クエリで同一の 3 つのテーブルを結合しているようです。これにより、結合を使用してこれが 1 つのクエリに統合されます。

于 2013-01-18T10:20:56.333 に答える
0

ここを見てください: 複数の行を1つの列にカンマで区切ることはできますか?

STUFFを使用してSQLServerでOracleのLISTAGG()をシミュレートします。

SELECT Column1,
  stuff((
   SELECT ', ' + Column2
     FROM tableName as t1
      where t1.Column1 = t2.Column1
       FOR XML PATH('')
     ), 1, 2, '')
 FROM tableName as t2
GROUP BY Column1
/

ここからコピー:https ://github.com/jOOQ/jOOQ/issues/1277

于 2013-01-18T15:07:35.010 に答える