with a as( select 1 id , 'A' product, 0 depth union all select 2 id , 'B' product, 1 depth union all select 3 id , 'C' product, 2 depth union all select 4 id , 'D' product, 2 depth union all select 5 id , 'E' product, 2 depth union all select 6 id , 'F' product, 1 depth union all select 7 id , 'G' product, 2 depth union all select 8 id , 'H' product, 2 depth union all select 9 id , 'I' product, 0 depth union all select 10 id , 'J' product, 1 depth union all select 11 id , 'K' product, 2 depth union all select 12 id , 'A' product, 2 depth union all select 13 id , 'B' product, 2 depth union all select 14 id , 'L' product, 1 depth union all select 15 id , 'E' product, 2 depth union all select 16 id , 'D' product, 2 depth ), b as ( select 'A' bundle_product , 'B' product, 1 sort union all select 'A' bundle_product , 'F' product, 2 sort union all select 'B' bundle_product , 'C' product, 1 sort union all select 'B' bundle_product , 'D' product, 2 sort union all select 'B' bundle_product , 'E' product, 3 sort union all select 'F' bundle_product , 'H' product, 1 sort union all select 'F' bundle_product , 'G' product, 2 sort union all select 'I' bundle_product , 'J' product, 1 sort union all select 'I' bundle_product , 'L' product, 2 sort union all select 'J' bundle_product , 'A' product, 1 sort union all select 'J' bundle_product , 'B' product, 2 sort union all select 'J' bundle_product , 'K' product, 3 sort union all select 'L' bundle_product , 'D' product, 1 sort union all select 'L' bundle_product , 'E' product, 2 sort )
테이블 A
id | product | depth |
1 | A | 0 |
2 | B | 1 |
3 | C | 2 |
4 | D | 2 |
5 | E | 2 |
6 | F | 1 |
7 | G | 2 |
8 | H | 2 |
9 | I | 0 |
10 | J | 1 |
11 | K | 2 |
12 | A | 2 |
13 | B | 2 |
14 | L | 1 |
15 | E | 2 |
16 | D | 2 |
테이블 B
bundle_product | product | sort |
A | B | 1 |
A | F | 2 |
B | C | 1 |
B | D | 2 |
B | E | 3 |
F | H | 1 |
F | G | 2 |
I | J | 1 |
I | L | 2 |
J | A | 1 |
J | B | 2 |
J | K | 3 |
L | D | 1 |
L | E | 2 |
1. 0depth 끼리는 id 순서가 빠른것
2. bundle 테이블의 sort 순서대로
조회를 하고싶은데요.
순서 | product |
1 | A |
2 | B |
3 | C |
4 | D |
5 | E |
6 | F |
7 | H |
8 | G |
9 | I |
10 | J |
11 | A |
12 | B |
13 | K |
14 | L |
15 | D |
16 | E |
최종 순서는 위와같이 나와야 하는데 방법을 모르겠습니다.
고수님들의 도움이 필요합니다