select * from t1 where c_idx=3102;
+-------+--------------+-----------+----------+
| idx | a_idx | b_idx | c_idx |
+-------+--------------+-----------+----------+
| 11298 | 0 | 5 | 3102 |
| 11299 | 1 | 6 | 3102 |
| 20500 | 0 | 8 | 3102 |
| 20501 | 0 | 7 | 3102 |
| 21879 | 0 | 12 | 3102 |
| 21880 | 0 | 17 | 3102 |
+-------+--------------+-----------+----------+
하면 위와같은 값이 출력 됩니다.
원하는 값은 묶여서 b_idx 가나오길원합니다
원하는값
b_idx c_idx
5,6,8,7,12,17 3102
이렇게 나오게할수있는 방법이있을까요?
1 2 3 4 5 6 7 8 9 10 11 12 13 | WITH tmp AS ( select 11298 as idx , 0 as a_idx , 5 as b_idx , 3102 as c_idx union all select 11299 as idx , 1 as a_idx , 6 as b_idx , 3102 as c_idx union all select 20500 as idx , 0 as a_idx , 8 as b_idx , 3102 as c_idx union all select 20501 as idx , 0 as a_idx , 7 as b_idx , 3102 as c_idx union all select 21879 as idx , 0 as a_idx , 12 as b_idx , 3102 as c_idx union all select 21880 as idx , 0 as a_idx , 17 as b_idx , 3102 as c_idx ) select group_concat( distinct (b_idx)) as gc_b_idx , group_concat( distinct (c_idx)) as gc_c_idx from tmp; |
group_concat 이라는 함수 사용해서 활용하시면 될 것 같습니다