I have the following SQL problem.
Scenario:
I have two tables: Change and ChangeTicket. There is a ratio of 1: n. One Change has cero or many changeTickets. No change no change. ChangeTicket has a status (open / closed / ...) The changeTicket field has a field that indicates how many minutes this change has passed.
A Change has a company and a month. There is at most one change per month.
I have to report for this company and for this month, the amount of minutes this change has occurred.
I wrote the following SQL statement.
select nvl(sum(service_req), 0) as SUM_REQ from Change_Ticket, Change where Change.company_id (+) = '0' and Change.month (+)='07' and Change.Id (+) = Change_Ticket.Change_Id
This is normal.
If there are no changes or tickets for this month and company data, then I get a zero value, which is converted to the cero usgin function of NVL.
The problem arises when I want to group information using status. If I add a grup suggestion
select Change_Ticket.status, nvl(sum(service_req), 0) as SUM_REQ from Change_Ticket, Change where Change.company_id (+) = '0' and Change.month (+)='07' and Change.Id (+) = Change_Ticket.Change_Id group by Change_Ticket.status
then my result will be empty. I understand that there is no status, and then the result set is somehow consistent, and then an empty result set is returned.
How can I avoid this problem. In this case, I need to report an empty status and cero as the sum.
(BTW, I also tried setting nvl (Change_Ticket.status, 'none') , but it didn't work)
Thank you very much in advance.
Louis