I occasionally encounter an error while executing the query below. However, when I rerun the query after the error occurs, it runs successfully. What could be causing this error?
WITH trial_courses AS (
SELECT _id, title
FROM dbonline_v2_courses
WHERE __hevo__marked_deleted = FALSE AND is_trial = true
),
-- 항해 결제자
hh_paid AS (
SELECT onlineuserid
FROM dbhanghae_v2_applicants
WHERE __hevo__marked_deleted = FALSE AND funnelid = '61066b826c10bd0689a3148a'
),
-- 내배캠 강의
gov_camp_courses AS (
SELECT _id
FROM dbonline_v2_courses
WHERE __hevo__marked_deleted = FALSE AND is_gov_training = true
),
-- 내배캠 합류자
gov_camp_enroll AS (
SELECT user_id
FROM dbonline_v2_enrolleds
WHERE __hevo__marked_deleted = FALSE AND course_id IN (SELECT _id FROM gov_camp_courses)
AND is_registered = True
),
main AS (
SELECT
distinct(us._id) as user_id,
us.phone,
us.name,
co.title,
start_date,
current_date,
end_date,
erd.updated_at,
extract(year from sysdate) - birthyear as age
from dbonline_v2_enrolleds erd
left join dbonline_v2_courses co
on erd.course_id = co._id
left join dbonline_v2_users us
on erd.user_id = us._id
where nvl(us.name, '') != ''
and us.phone is not null
and us.name is not null
and erd.__hevo__marked_deleted = false
and us.is_test is not true
and us.marketing = 'true'
and co._id = '65b31ccd173c32f5c61bdf29'
)
SELECT *
FROM main as o
WHERE age between 20 and 35
-- 항해 결제자 제외
AND NOT EXISTS (
SELECT 1
FROM hh_paid hp
WHERE hp.onlineuserid = o.user_id
)
-- 내배캠 합류자 제외
AND NOT EXISTS (
SELECT 1
FROM gov_camp_enroll gc
WHERE gc.user_id = o.user_id
)