안녕하세요. 오늘도 염치없지만 질문하나 드리려고 합니다.
우선 현재 테이블을 예시를 하나 작성하도록 하겠습니다.
현재 회원의 permission = 4
tb_goodsSearch AS g
goodsNo | goodsNm | |
100000 | 추가상품1 | |
100001 | 추가상품2 | |
100002 | 추가상품3 | |
100003 | 추가상품4 | |
100004 | 추가상품5 | |
100005 | 추가상품6 | |
100006 | 추가상품7 | |
100007 | 추가상품8 | |
100008 | 추가상품9 | |
100009 | 추가상품10 | |
100010 | 추가상품11 | |
100011 | 추가상품12 | |
100012 | 추가상품13 | |
100013 | 추가상품14 | |
100014 | 추가상품15 | |
100015 | 추가상품16 | |
100016 | 추가상품17 | |
100017 | 추가상품18 | |
100018 | 추가상품19 | |
100019 | 추가상품20 |
tb_goodsLinkCategory AS glc
goodsNo | cateCd |
100000 |
001 |
100001 | 001 |
100002 | 001 |
100003 | 001 |
100004 | 002 |
100005 | 002 |
100006 | 002 |
100007 | 002 |
100008 | 003 |
100009 | 003 |
100010 | 003 |
100011 | 003 |
100012 | 004 |
100013 | 004 |
100014 | 004 |
100015 | 004 |
100016 | 005 |
100017 | 005 |
100018 | 005 |
100019 | 005 |
tb_categoryGoods AS cg
categoryCode | categoryPermissionGroup |
001 |
2||3 |
002 | 2||3 |
003 | 2||4 |
004 | 2||4 |
005 |
아 테이블 예시를 정확히 들었는지 걱정되네요 . .ㅎㅎ
회원이 추가상품이라는 키워드로 검색을 했을 떄 원하는 리스트를 보여주고싶습니다.
결과적으로 tb_categoryGoods에 categoryPermissionGroup이 회원이 가진 permission(4)을 포함하고 있거나 혹은 공백이거나 인 경우에 goodsNo를 출력하고 싶습니다.
설명이 다소 모자라거나 다른 부분이 있을 수 있는데.. 양해부탁드리겠습니다.. 누락된 설명이 있다면 말씀 부탁드리겠습니다!
WITH tb_goodsSearch AS -- g ( SELECT 100000 goodsNo, '추가상품1' goodsNm UNION ALL SELECT 100001, '추가상품2' UNION ALL SELECT 100002, '추가상품3' UNION ALL SELECT 100003, '추가상품4' UNION ALL SELECT 100004, '추가상품5' UNION ALL SELECT 100005, '추가상품6' UNION ALL SELECT 100006, '추가상품7' UNION ALL SELECT 100007, '추가상품8' UNION ALL SELECT 100008, '추가상품9' UNION ALL SELECT 100009, '추가상품10' UNION ALL SELECT 100010, '추가상품11' UNION ALL SELECT 100011, '추가상품12' UNION ALL SELECT 100012, '추가상품13' UNION ALL SELECT 100013, '추가상품14' UNION ALL SELECT 100014, '추가상품15' UNION ALL SELECT 100015, '추가상품16' UNION ALL SELECT 100016, '추가상품17' UNION ALL SELECT 100017, '추가상품18' UNION ALL SELECT 100018, '추가상품19' UNION ALL SELECT 100019, '추가상품20' ) , tb_goodsLinkCategory AS -- glc ( SELECT 100000 goodsNo, '001' cateCd UNION ALL SELECT 100001, '001' UNION ALL SELECT 100002, '001' UNION ALL SELECT 100003, '001' UNION ALL SELECT 100004, '002' UNION ALL SELECT 100005, '002' UNION ALL SELECT 100006, '002' UNION ALL SELECT 100007, '002' UNION ALL SELECT 100008, '003' UNION ALL SELECT 100009, '003' UNION ALL SELECT 100010, '003' UNION ALL SELECT 100011, '003' UNION ALL SELECT 100012, '004' UNION ALL SELECT 100013, '004' UNION ALL SELECT 100014, '004' UNION ALL SELECT 100015, '004' UNION ALL SELECT 100016, '005' UNION ALL SELECT 100017, '005' UNION ALL SELECT 100018, '005' UNION ALL SELECT 100019, '005' ) , tb_categoryGoods AS -- cg ( SELECT '001' categoryCode, '2||3' categoryPermissionGroup UNION ALL SELECT '002', '2||3' UNION ALL SELECT '003', '2||4' UNION ALL SELECT '004', '2||4' UNION ALL SELECT '005', null ) SELECT g.goodsNo , g.goodsNm , glc.cateCd FROM tb_goodsSearch g INNER JOIN tb_goodsLinkCategory glc ON g.goodsNo = glc.goodsNo INNER JOIN tb_categoryGoods cg ON glc.cateCd = cg.categoryCode WHERE g.goodsNm LIKE '추가상품%' AND ( FIND_IN_SET('4', REPLACE(cg.categoryPermissionGroup, '||', ',')) > 0 OR cg.categoryPermissionGroup IS NULL ) ;