MySQLで。実際、結果は特に「リレーショナル」ではありません。なぜなら、各列は別のリストであるからです。
join
キーがないため、
join
を実行することはできません。
MySQLで変数を使用して生成し、集計を使用できます。
select id_table1,
max(t2_date) as t2_date,
max(t2_desc) as t2_desc,
max(t3_date) as t3_date,
max(t3_desc) as t3_desc
from ((select id_table1, NULL as t2_date, NULL as t2_desc, NULL as t3_date, NULL as t3_desc, 1 as rn
from table1 t1
) t1 union all
(select fk_table1, date as t2_date, description as t2_desc, NULL as t3_date, NULL as t3_desc,
(@rn1 := if(@fk1 = fk_table1, @rn1 + 1,
if(@fk1 := fk_table1, 1, 1)
)
) as rn
from table1 t1 cross join
(select @rn1 := 0, @fk1 := 0) params
order by fk_table1, date
) t1 union all
(select fk_table1, NULL, NULL, date as t3_date, description as t3_desc
(@rn2 := if(@fk2 = fk_table1, @rn2 + 1,
if(@fk2 := fk_table1, 1, 1)
)
) as rn
from table1 t1 cross join
(select @rn2 := 0, @fk2 := 0) params
order by fk_table1, date
)
) t
group by id_table1, rn;
「fk_table1」列のテーブルの中で 'JOIN'を実行します。 – Rahul