select adjust.id, adjust.orginal_ticket_id, adjust.trans_history_id , adjust.ticket_id
from trans_history_shared adjust
where cdr_type=201
and adjust.event_timestamp <= v_end_time_summary
and adjust.create_date >= v_start_time_summary
and adjust.create_date < v_end_time
and exists (
select origin.ticket_id
from trans_history_shared origin
where origin.ticket_id=adjust.orginal_ticket_id
and origin.event_timestamp <= v_end_time_summary
and origin.create_date >= v_start_time_summary
and origin.create_date < v_end_time
and (origin.revenue_date is null or origin.revenue_date = v_start_time_summary)
)
and ticket_id = (
select latest.ticket_id
from trans_history_shared latest
where latest.orginal_ticket_id = adjust.orginal_ticket_id
and cdr_type=201
and latest.event_timestamp <= v_end_time_summary
and latest.create_date >= v_start_time_summary
and latest.create_date < v_end_time
and (latest.revenue_date is null or latest.revenue_date=v_start_time_summary)
order by latest.create_date desc, latest.event_timestamp desc
fetch first 1 rows only);
Hi all, I'm trying to implement this query inside spark sql, but it's giving me an error saying correlated scalar subqueries must be aggregated. Could you guys perhaps help me how to fix this? Thank you for reading and have a nice day!