MySQL Forums
Forum List  »  Newbie

Query that counts occurrences and groups by hour
Posted by: bob owens
Date: March 14, 2011 07:27PM

I am trying to come with a query that will count the number of occurences of specific values in a field grouped by hour.

the data that I am provided looks like this:
3 fields date_occurred, time_occurred ans event.

Date_occurred time_occurred event
2011-3-10 14:03 scd1
2011-3-10 14:06 scd1
2011-3-10 14:08 scd2
2011-3-10 14:14 scd3
2011-3-10 14:17 scd1
2011-3-10 14:22 scd3
2011-3-10 14:23 scd3
2011-3-10 14:48 scd2
2011-3-10 15:03 scd1
2011-3-10 15:23 scd3
2011-3-10 15:27 scd3
2011-3-10 16:07 scd1
2011-3-10 16:18 scd1
2011-3-10 16:48 scd1

The result that I would like to get would look something like this:


hour scd1_num scd2_num scd3_num
14:00 3 2 3
15:00 1 0 2
16:00 0 0 3

return 4 columns, hour, scd1_num, scd2_num, scd3_num, The hour in which the events occurred and how many of each type.

I will be specifying the date and then reporting the data for the 24 hour period.

After hours of googling, I am getting nowhere with this.

Any assistance you may offer will be greatly appreciated.

Options: ReplyQuote


Subject
Written By
Posted
Query that counts occurrences and groups by hour
March 14, 2011 07:27PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.