SELECT PC.SHOW_ORDER CAT_SHOW_ORDER, PC.CAT_CODE, PC.CAT_NAME, PCM.PRO_CODE, PCM.SHOW_ORDER PRO_SHOW_ORDER
FROM PRO_CATS PC
JOIN PRO_CATS_MAP PCM ON PCM.CAT_CODE = PC.CAT_CODE
JOIN (SELECT PRO_CODE, MAX(PLAN_VERSION||VERSION) FROM PRODUCTS
WHERE (VARCHAR_FORMAT(TIMESTAMP_FORMAT(CHAR(START_DATE), 'YYYYMMDD'), 'YYYYMMDD') <= '20190905'
AND VARCHAR_FORMAT(TIMESTAMP_FORMAT(CHAR(END_DATE), 'YYYYMMDD'), 'YYYYMMDD') >= '20190905'
) AND VARCHAR_FORMAT(CURRENT TIMESTAMP, 'YYYYMMDD') || CHAR(HOUR(CURRENT TIME))
NOT BETWEEN COALESCE(VARCHAR_FORMAT(TIMESTAMP_FORMAT(CHAR(HIDDEN_START_DATE), 'YYYYMMDD'), 'YYYYMMDD') || HIDDEN_START_TIME, '9999123100')
AND COALESCE(VARCHAR_FORMAT(TIMESTAMP_FORMAT(CHAR(HIDDEN_END_DATE), 'YYYYMMDD'), 'YYYYMMDD') || HIDDEN_END_TIME, '9999123100')
GROUP BY PRO_CODE) P ON P.PRO_CODE = PCM.PRO_CODE
WHERE PC.OPEN_YN = 'Y' AND PC.SHOW_YN = 'Y'
ORDER BY PC.SHOW_ORDER, PCM.SHOW_ORDER