Skip to content
Advertisement

How to add fictional rows to an SQL results in Oracle without à grouping

here is my issue, I’m working on an existing big report and they want me to add fictional rows with specifics values each time row in database meet a condition (let’s say status = Canceld) I simplified the query (1000 lines of SQL Code) to this :

if I have two table A and B :

and the query is like that :

and the results are like that :

now what I need to do is insert fictional rows whenever the Status is Canceled like that : for each row where Status = Canceled add a row with same Name and Estimated column, Status Scheduled and Real = 0. the result should look like : (I added ** before the fictional rows)

I tried a join or UNION with dual but I don’t figure out what’s missing. thank you a lot

Advertisement

Answer

You can give this a try, note that C is an inline view which is used to select the fictional row and does a union with your existing resultset.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement