質問するログイン新規登録

回答編集履歴

1

追記

2021/10/11 07:07

投稿

sazi
sazi

スコア25430

answer CHANGED
@@ -12,4 +12,21 @@
12
12
  select 親部品, 中間完成品, 子品番, 生産場所
13
13
  from bom
14
14
  where lvl > 1
15
+ ```
16
+ 因みに、階層のパンくずを表示するとしたら以下になります。
17
+ ```SQL
18
+ with bom(親品番, 子品番, 生産場所, 親部品, 中間完成品, 階層, lvl) as (
19
+ select 親品番,子品番, 生産場所 , 親品番 as 親部品, 子品番 as 中間完成品
20
+ , 親品番 || ' > ' || 子品番, 1
21
+ from sample
22
+ where 親品番 like '車'
23
+ union all
24
+ select s.親品番, s.子品番, s.生産場所, b.親部品, b.中間完成品
25
+ , 階層 || ' > ' || s.子品番, b.lvl+1
26
+ from bom b inner join sample s
27
+ on b.子品番=s.親品番
28
+ )
29
+ select 親部品, 中間完成品, 子品番, 生産場所, 階層
30
+ from bom
31
+ where lvl > 1
15
32
  ```