-- attraction 필드 값 예시
[{"order": 1, "orderDate": 1, "attractionId": 1886054}, {"order": 2, "orderDate": 1, "attractionId": 1920563}, {"order": 1, "orderDate": 2, "attractionId": 136249}, {"order": 2, "orderDate": 2, "attractionId": 136310}]
attraction_plan 테이블에 있는 attraction 필드는 JSON 타입이고, JSON 객체를 담고 있는 배열이다.
attractionId와 관광지 테이블의 attraction_info 테이블의 content_id 필드의 값을 이용해서 조인을 했다.
select attractionId, at.title, at.first_image, at.addr1, at.content_id, orderNum, orderDate
from enjoytrip.attraction_plan ap,
json_table(ap.attraction, '$[*]' columns (
attractionId int path '$.attractionId',
orderNum int path '$.order',
orderDate int path '$.orderDate'
)) as jt
join attraction_info at on jt.attractionId = at.content_id
where attraction_plan_id = 1;
;
반응형
'DB > MySQL' 카테고리의 다른 글
[MySQL] Dump (0) | 2024.05.28 |
---|---|
Mysql Event Scheduler (0) | 2023.12.28 |
연관 관계에 있는 데이터 삭제 (0) | 2023.11.19 |
MySQL 데이터 타입 (0) | 2023.05.21 |
MySQL 계정 (0) | 2023.01.21 |