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 6363017
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T23:58:57+00:00 2026-05-24T23:58:57+00:00

This is a summary version of the problems I am encountering, but hits the

  • 0

This is a summary version of the problems I am encountering, but hits the nub of my problem. The real problem involves huge UNION groups of monthly data tables, but the SQL would be huge and add nothing. So:

SELECT entity_id, 
    sum(day_call_time) as day_call_time
            from (
                SELECT entity_id, 
                    sum(answered_day_call_time) as day_call_time
                    FROM XCDRDNCSum201108 
                    where (day_of_the_month >= 10 AND  day_of_the_month<=24) 
                    and LPAD(core_range,4,"0")="0987" 
                    and LPAD(subrange,3,"0")="654" 
                    and SUBSTR(LPAD(core_number,7,"0"),4,7)="3210"
            ) as summary

is the problem: when the table in the subquery XCDRDNCSum201108 returns no rows, because it is a sum, the column values contain null. And entity_id is part of the primary key, and cannot be null.
If I take out the sum, and just query entity_id, the subquery contains no rows, and thus the outer query does not fail, but when I use sum, I get error 1048 Column ‘entity_id’ cannot be null

how do I work around this problem ? Sometimes there is no data.

  • 1 1 Answer
  • 0 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-24T23:58:57+00:00Added an answer on May 24, 2026 at 11:58 pm

    You are completely overworking the query… pre-summing inside, then summing again outside. In addition, I understand you are not a DBA, but if you are ever doing an aggregation, you TYPICALLY need the criteria that its grouped by. In the case presented here, you are getting sum of calls for all entity IDs. So you must have a group by any non-aggregates. However, if all you care about is the Grand total WITHOUT respect to the entity_ID, then you could skip the group by, but would also NOT include the actual entity ID…

    If you want inclusive to show actual time per specific entity ID…

    SELECT
          entity_id, 
          sum(answered_day_call_time) as day_call_time,
          count(*) number_of_calls
       FROM
          XCDRDNCSum201108 
       where
              (day_of_the_month >= 10 AND  day_of_the_month<=24) 
          and LPAD(core_range,4,"0")="0987" 
          and LPAD(subrange,3,"0")="654" 
          and SUBSTR(LPAD(core_number,7,"0"),4,7)="3210"
       group by
          entity_id
    

    This would result in something like (fictitious data)

    Entity_ID   Day_Call_Time   Number_Of_Calls
    1           10              3
    2           45              4
    3           27              2
    

    If all you cared about were the total call times

    SELECT
          sum(answered_day_call_time) as day_call_time,
          count(*) number_of_calls
       FROM
          XCDRDNCSum201108 
       where
              (day_of_the_month >= 10 AND  day_of_the_month<=24) 
          and LPAD(core_range,4,"0")="0987" 
          and LPAD(subrange,3,"0")="654" 
          and SUBSTR(LPAD(core_number,7,"0"),4,7)="3210"
    

    This would result in something like (fictitious data)

    Day_Call_Time   Number_Of_Calls
    82              9
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My items are listed as follows; This is just a summary of course. But
[EDIT: This problem was a result of a bug within version 3.7.6] The following
This is what i want to do: I want /summary.php to include 5 latest
I have an object Title : foo Summary : foo bar Body : this
Suppose I have this interface public interface IFoo { ///<summary> /// Foo method ///</summary>
/// <summary> /// This method does something... /// </summary> public void DoSomething() { //
How can I write this code more cleanly/concisely? /// <summary> /// Creates a set
I recently found out about C# extension methods and wrote this one: /// <summary>
I have a file that is similar to this: <many lines of stuff> SUMMARY:
This is a bit of a long shot, but if anyone can figure it

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.