473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Number of records per hour

Hi there
I have a table which contains a timestamp/datetime row amongst others.

I would like to create a query that displays the number of entries per hour during the current day. Maybe even showing 0 for hours that have no entries.

Now I know I could simply loop through all the hours from 00 to 23 in order to produce the required output but somehow I feel a more efficient way is possible.

San anyone give me a pointer or example?

I have a MySQL v4.1 database
Mar 29 '08 #1
1 2897
ronverdonk
4,258 Expert 4TB
Welcome to The Scripts!

I have this table
Expand|Select|Wrap|Line Numbers
  1. +----+----------+
  2. | id | hit      |
  3. +----+----------+
  4. |  1 | 01:10:20 |
  5. |  2 | 01:20:20 |
  6. |  3 | 01:30:20 |
  7. |  4 | 02:30:20 |
  8. |  5 | 03:30:20 |
  9. |  6 | 03:50:20 |
  10. |  7 | 04:50:20 |
  11. |  8 | 05:50:20 |
  12. |  9 | 07:50:20 |
  13. | 10 | 08:50:20 |
  14. | 11 | 08:52:20 |
  15. | 12 | 09:52:20 |
  16. +----+----------+
I run this query
Expand|Select|Wrap|Line Numbers
  1. select substr(hit,1,2) as hour, count(*) from hits as hits_per_hour group by hour;
I get this result
Expand|Select|Wrap|Line Numbers
  1. +------+---------------+
  2. | hour | hits_per_hour |
  3. +------+---------------+
  4. | 01   |             3 |
  5. | 02   |             1 |
  6. | 03   |             2 |
  7. | 04   |             1 |
  8. | 05   |             1 |
  9. | 07   |             1 |
  10. | 08   |             2 |
  11. | 09   |             1 |
  12. +------+---------------+
Try it out and adapt where necessary.

Ronald
Mar 29 '08 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

21
by: Trint Smith | last post by:
This will be a customer number that is automatically assigned. I want it to be fast (so that it doesn't have to be checked for existance in sql server) and impossible to ever reoccure. Could it...
2
by: Chris Leffer | last post by:
Hi. My application reads a table that stores data as time, eg: 02:17:31 I need to read this value and convert it to an integer, representing the total number of seconds. At this moment I am...
4
by: Got2Go | last post by:
Hello Group, I have a table that has millions of records in it. About 100 records are added every 5 minutes (one per OIDID) (the sample provided below has data for 2 OIDIDs (99 and 100) And I...
8
by: King | last post by:
Hi I have following MS Acess query Here is the query ID Name Prgm ID Client ID Date Start Time End Time Minutes C4 Trisha TIP DEK0703 7 /7 /2006...
19
by: eric.nave | last post by:
this is a slight change to a fequently asked question around here. I have a table which contains a "sortorder" column where a user can specify some arbitrary order for records to be displayed in. ...
3
by: wvmbark | last post by:
First time poster... I just found this forum and it appears there's plenty of people here that could make short work of problem that's been driving me absolutely bonkers for months. Every day we...
6
by: drazenj | last post by:
Hi , sorry for my english ... I work in high school as a teacher and try to make CLASS SCHEDULE (TIME schedule) for my collegues and for students . My problem is that I don't know how to...
5
by: lucianone41 | last post by:
Hello everyone, I´m starting to learn Access , SQL and a bit of VB. My problem is the following: I have two tables, one of them contains the records for missing points on a GPS system (called the...
3
by: bobdurie | last post by:
Hi, We have a Java application that runs against a variety of backends including Oracle and MSSql 2000 and 2005. Our application has a handful of active tables that are constantly being...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.