Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 371725
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 12, 20262026-05-12T14:08:31+00:00 2026-05-12T14:08:31+00:00

I have the following SQL problem. Scenario: I have two tables: Change and ChangeTicket.

  • 0

I have the following SQL problem.

Scenario:

I have two tables: Change and ChangeTicket.
There is a 1:n relationship. One Change has cero or many changeTickets.
No change means no changeTickets.
A changeTicket has a status (open/closed/…)
A changeTicket has a field representing how many minutes took this change.

A Change has a company and a month. There is at most ONE change in the month.

I have to report for a given company and for a given month the sum of minutes
a given change took.

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 OK.

If for the given month and the given company there are neither changes nor tickets
then I get a null value which is converted to cero usgin the NVL function.

The problem arises when I want to group the information using the status.
If I add a grup clause

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 is the empty set.
I understand that there is no status and then the resulting set is
somehow consistent and then an empty resulting set is returned.

How can I avoid this problem. In this case I need to report an
empty status and cero as the the sum.

(BTW, I’ve also tried putting nvl(Change_Ticket.status, ‘none’) but didn’t work)

Thanks a lot in advance.

Luis

  • 1 1 Answer
  • 3 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-12T14:08:32+00:00Added an answer on May 12, 2026 at 2:08 pm

    I think to achieve what you want you would need to do this:

    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
    union all
    select '' as STATUS, 0 as SUM_REQ
    from dual
    where not exists (select null from Change_ticket)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a problem creating the following SQL Statement using LINQ & C# select
I have the following SQL code that runs against a Change Request database. Each
I have a database that has two tables. These two tables are defined as:
So I have the following SQL code which calculates the pearson correlation between two
I'm a beginner in SQL and I have the following problem in SQL. I
I have two tables that I am using Linq to SQL with. The tables
In SQL Server 2008, I have the following tables: CREATE TABLE samples (SampleID int,
I have the following SQL statement which has a very bad performance: SELECT frmInstLastModifiedDate
I have following SQL query SELECT TOP 10000 AVG(DailyNodeAvailability.Availability) AS AVERAGE_of_Availability FROM Nodes INNER
Hi I have following sql statement that gives me the the first_name and total

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.