I have a SQL Teradata table with 4 columns. Cust_id & Act_num are indexed columns, and Date is not indexed.
I need to filter the data on the DATE column.
Select
Cust_id,
Act_num,
Date,
Max(score) Max_Score
from
table_name
where
date >= 1240601
group by
1, 2, 3
The query takes a long time to run, as it is filtering on the non-indexed column, and when I run that query to retrieve data for more than 6 months, it shows error insufficient spool space.
I have read only access and limited spool space which cannot be changed.
Please suggest ways to optimize the query. I already tried self join and exists
where date >=1240601 and date<1240901, next aswhere date >=1240901 and date<1241201and so on. Your query takes filtered rowswhere date >=1240601then spool to sort on(Cust_id,Act_num,Date) and group by ...date '2024-06-01'INDEX(date, cust_id, acct_id, score).