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

  • Home
  • SEARCH
  • 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 9146303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:43:05+00:00 2026-06-17T10:43:05+00:00

I have a three mysql database table which contains the call record of the

  • 0

I have a three mysql database table which contains the call record of the customer company. I want to fetch the data from the database for a company group by per hour. If there is no data for an hour, it should return Zero.

I am executing this query, but am getting the result for that hour only for which there is a data in the database.

This is my query.

select ph_Plans.Comp_ID, Plan_Type, ph_Companies.CompanyName,
    (sum(call_length_billable)*100)/(Plan_Limit*60) as total,
    hour(calldate)
from ph_Plans
join ph_Companies
    on ph_Companies.Comp_ID = ph_Plans.Comp_ID
join cdr
    on cdr.CompanyName = ph_Companies.CompanyName
where Plan_Type='Per_Min'
    and date(calldate)='2012-10-01'
    and ph_Companies.CompanyName='"ReadySpace-EN"'
group by hour(calldate);

This is the result that am getting.

+---------+-----------+-----------------+--------+----------------+
| Comp_ID | Plan_Type | CompanyName     | total  | hour(calldate) |
+---------+-----------+-----------------+--------+----------------+
|      44 | Per_Min   | "ReadySpace-EN" | 3.7467 |              1 |
|      44 | Per_Min   | "ReadySpace-EN" | 9.4933 |             18 |
|      44 | Per_Min   | "ReadySpace-EN" | 1.6600 |             20 |
|      44 | Per_Min   | "ReadySpace-EN" | 3.7333 |             21 |
|      44 | Per_Min   | "ReadySpace-EN" | 4.6067 |              2 |
|      44 | Per_Min   | "ReadySpace-EN" | 7.6533 |             23 |
+---------+-----------+-----------------+--------+----------------+

But I want the result from zeroth hour to 23 hour. If no data then it should return zero.

  • 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-06-17T10:43:07+00:00Added an answer on June 17, 2026 at 10:43 am

    When doing a JOIN, you only JOIN on tables that both have data that corresponds to the Columns being JOINed. What you want to do is a LEFT JOIN when you still want results where there is no corresponding data in the other table.

    Something like this:

    select ph_Plans.Comp_ID, Plan_Type, ph_Companies.CompanyName,
        if(call_length_billable IS NULL, 0, (sum(call_length_billable)*100)/(Plan_Limit*60)) as total,
        ifnull(hour(calldate), 0) hour
    from ph_Plans
    left join ph_Companies
        on ph_Companies.Comp_ID = ph_Plans.Comp_ID
    left join cdr
        on cdr.CompanyName = ph_Companies.CompanyName
    where Plan_Type='Per_Min'
        and (date(calldate)='2012-10-01' OR calldate IS NULL)
        and (ph_Companies.CompanyName='"ReadySpace-EN"' OR ph_Companies.CompanyName IS NULL)
    group by hour(calldate);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(on mysql database), I want to have a table which contains different variables for
I have three mysql table from same database Db1. Three tables have following columns.
I have a MySQL database which contains a table of users. The primary key
I have a table with a field which contains strings in my MySQL database.
I have a table in my MySQL database which contains records of activity. It
I have the following task: there are a simple table from mysql database: <html>
Learning php! I have a sql database which contains a table called 'images' which
i have a php code which selects and shows data from my 'elections' table.
I have a database which contains an Assignment table. The table looks like this:
I have a table, matches , which contains sports fixture data with fields including

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.