Note that there are some explanatory texts on larger screens.

plurals
  1. POMysql query group by per hour return zero if no data found for an hour
    primarykey
    data
    text
    <p>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.</p> <p>I am executing this query, but am getting the result for that hour only for which there is a data in the database.</p> <p>This is my query.</p> <pre><code>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); </code></pre> <p>This is the result that am getting.</p> <pre><code>+---------+-----------+-----------------+--------+----------------+ | 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 | +---------+-----------+-----------------+--------+----------------+ </code></pre> <p>But I want the result from zeroth hour to 23 hour. If no data then it should return zero.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload