0

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
thatjeffsmith
  • 20,522
  • 6
  • 37
  • 120

1 Answers1

0

see the old-school SQLPLUS BREAK (docs) reporting option, it also works in SQL Developer if you run queries as a script

set pagesize 200
break on department_id
clear screen

select department_id, first_Name, last_name
from employees
order by department_id

enter image description here

You mentioned Excel, you can copy/paste this output over, no worries.

enter image description here

Disclaimer: I work for oracle and am a product manager for SQL Developer

thatjeffsmith
  • 20,522
  • 6
  • 37
  • 120