We have a running report that sums the number of records loaded and counts the number of stores by date loaded, based on a daily job that picks up a file and loads to a list. Our issue is that if the file isn't posted or the job fails, the SQL result repeats the same result for those days. While we can manually adjust this in excel, I'd like to figure out a way to skip over repeated values in the results set. The idea is that I'll create a subquery that assigns row numbers to the TOTAL_RECORDS_LOADED, partitioned by TOTAL_RECORDS_LOADED. Then the row numbers will count up when the total records loaded number is the same and I can isolate the results to only those with a row number of 1. Here is what I have with the Error: java.sql.SQLSyntaxErrorException: ORA-00923: FROM keyword not found where expected.
SELECT To_char(r.loaded_date, 'YYYY-MM-DD') AS loaded_date,
d.stores,
r.total_records_loaded
FROM (SELECT r.total_records_loaded,
To_char(r.loaded_date, 'YYYY-MM-DD') AS date,
Row_number()
OVER (
partition BY r.total_records_loaded
ORDER BY Trunc(date) DESC ) ROW_NUMBER FROM
(SELECT Trunc(loaded_date) AS loaded_date,
Sum(records_loaded) AS TOTAL_RECORDS_LOADED
FROM $a$
GROUP BY Trunc(loaded_date))R,
(SELECT Trunc(loaded_date) AS LOADED_DATE,
Count(storenumber) AS STORES
FROM $a$
GROUP BY Trunc(loaded_date))D
WHERE r.loaded_date = d.loaded_date
AND ROW_NUMBER = '1'
ORDER BY To_char(r.loaded_date, 'YYYY-MM-DD') DESC