Now the code is finally using the code tags. That's taken weeks to get this far, so I guess I should be grateful!
What I asked for is:
- A CREATE TABLE statement to create the test table. (Haven't really got that because I don't have your schema, so your query to build the test table is meaningless to me.)
- INSERT statements to populate the test table. (See previous point.)
- An explanation of where the start and end dates are coming from. Are they parameters in the query, or something else. (From your script I can see these are hardcoded, so they are effectively constants. Didn't need the whole script. You could have just said they were constants.)
- A mock-up of the output you would expect to see from the query, based on the test data you post. I mean literally what SQL*Plus is meant to output if you were able to write the query. (Your problem is with a query. Let's deal with this in isolation. A query can be run in SQL*Plus and it will give output. Even if you can't write a query, you can fake what the output should look like and thereby give me a clue as to what you are trying to do.
I can see the problem, but I'm not going to say what it is until you provide me with what I asked for. Why? Because I'm trying to teach you how to correctly formulate a question so you don't piss me off again, or anyone else on any other forum. This is really basic stuff. If you can't formulate a reasonable question, then people will be very reluctant to help you.
PS. If you had ever bothered to read the sticky note at the top of this forum, it would have been obvious many weeks ago what you should be doing:viewtopic.php?f=2&t=6261