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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T09:26:27+00:00 2026-06-12T09:26:27+00:00

I have a question about a SQL query I am trying to write. I

  • 0

I have a question about a SQL query I am trying to write.

I need to query data from a database.
The database has, amongst others, these 3 fields:

Account_ID #, Date_Created, Time_Created

I need to write a query that tells me how many accounts were opened per hour.

I have written said query, but there are times that there were 0 accounts created, so these “hours” are not populated in the results.

For example:

Volume Date__Hour
435 12-Aug-12 03
213 12-Aug-12 04
125 12-Aug-12 06

As seen in the example above, hour 5 did not have any accounts opened.

Is there a way that the result can populate the hour but and display 0 accounts opened for this hour?
Example of how I want my results to look like:

Volume Date_Hour
435 12-Aug-12 03
213 12-Aug-12 04
0 12-Aug-12 05
125 12-Aug-12 06

Thanks!

Update: This is what I have so far

SELECT count(*) as num_apps, to_date(created_ts,'DD-Mon-RR') as app_date, to_char(created_ts,'HH24') as app_hour 
FROM accounts 
WHERE To_Date(created_ts,'DD-Mon-RR') >= To_Date('16-Aug-12','DD-Mon-RR') 
GROUP BY To_Date(created_ts,'DD-Mon-RR'), To_Char(created_ts,'HH24') 
ORDER BY app_date, app_hour
  • 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-12T09:26:28+00:00Added an answer on June 12, 2026 at 9:26 am

    To get the results you want, you will need to create a table (or use a query to generate a “temp” table) and then use a left join to your calculation query to get rows for every hour – even those with 0 volume.

    For example, assume I have a table with app_date and app_hour fields. Also assume that this table has a row for every day/hour you wish to report on.

    The query would be:

    SELECT NVL(c.num_apps,0) as num_apps, t.app_date, t.app_hour
        FROM time_table t
        LEFT OUTER JOIN 
        (
        SELECT count(*) as num_apps, to_date(created_ts,'DD-Mon-RR') as app_date, to_char(created_ts,'HH24') as app_hour 
        FROM accounts 
        WHERE To_Date(created_ts,'DD-Mon-RR') >= To_Date('16-Aug-12','DD-Mon-RR') 
        GROUP BY To_Date(created_ts,'DD-Mon-RR'), To_Char(created_ts,'HH24') 
        ORDER BY app_date, app_hour
        ) c ON (t.app_date = c.app_date AND t.app_hour = c.app_hour)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have question about the sql query. I am trying to make the query
I want to make one question about oracle/sql query. I have some data like
i have a general question about how sql server evaluates the joins.The query is
I have some questions about importing data from Excel/CSV File into SQL Server. Let
I have a question about JOINS. Does Sql JOINs reduce performance in a query?
I have a question about a specific query I'm writing in a SQL Server
I have a question about SQL Server indexes. I'm not a DBA and assume
I have question about XSLT1.0. The task is to write out in HTML all
I have question about interpreting strings as packed binary data in C++. In python,
My question about My SQL is, I have a table where users enter time

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.