select count(*) from (
SELECT trade_type, txn_tms, pay_type, txn_num, txn_amt, shift_id, DEVICE_NID, cur_station
FROM AFC_CC_USER.DETAIL_NOD_TRANSACTION_RECORD_NORMAL
WHERE SUBSTR(DEVICE_NID, 5, 2) = '03'
UNION ALL
SELECT trade_type, txn_tms, pay_type, txn_num, txn_amt, shift_id, DEVICE_NID, cur_station
FROM AFC_CC_USER.DETAIL_NOD_TRANSACTION_RECORD_ADJUST
WHERE SUBSTR(DEVICE_NID, 5, 2) = '03'
)a
left join tbl_civil_service b on a.shift_id = b.shift_id AND TO_CHAR(a.TXN_TMS, 'YYYY-MM-DD') = TO_CHAR(b.CUR_TMS, 'YYYY-MM-DD')
WHERE a.txn_tms >= '2023-07-26 00:00:00' AND a.txn_tms <= '2023-07-26 23:00:00'
这段代码有什么问题,大家帮忙看看解答一下,a表26号就101条数据,b表15条,但是left join之后就变几千条了,咋优化