Advertisement

05.20.2008 at 08:20AM PDT, ID: 23417509
[x]
Attachment Details
[x]
The Solution Rating System

With so many solutions, how can you tell which solutions are most likely to help you and which ones are not? To provide you with a tool to use, we rate our solutions based on various elements that most accurately determine if a solution is a quality solution. To explain what factors affect the solution rating, here are the elements we take into consideration when formulating our solution rating.

  • The Grade of the Solution
  • The Zone Rank of the Expert Providing the Solution
  • The Number of Author and Expert Comments
  • The Number of Experts Contributing
  • The Feedback of the Community

Your Input Matters
Because of the way the system is set up, the most important variable in this equation is you. As a member of Experts Exchange, you are able to cast your vote on the quality of the solutions in regard to how complete, accurate, helpful and easy to understand each solution is. When you provide your feedback, each rating is adjusted accordingly. So, if you see a solution that has a poor rating that you think is a good solution, let us know by rating it. As you do, the rating will be adjusted and will become more accurate for other members of our site.

If you have any suggestions that you would like to make for our rating system, please ask a question in the Suggestions Zone of Community Support.

Thank you!

8.0

select count records grouped by datetime field, but groups made on an per hour basis

Asked by ciuly in MySQL Server, SQL Query Syntax

It's been over 3 years since I last done complex db queries. I've only worked with basic queries and now I just can't seem to be able to figure out this one.

I have a table in MYSQL (4.1.22) like (operDate, operTime) where operDate is the datetime when the operation was made and operTime is the time it took for the operation to complete.

records are inserted every minute. (data is then compacted/archived and finally deleted after specified periods of time, so table will not grow beyond about 200.000 records)

what I'm trying to do eventually is plot a graphic representation of the time for a given period.
to complicate things even more, my operTime has 2 meanings:
- if it's greater than a specified value (for example 2000 (miliseconds)), the operation timedout
- otherwise, operation was successful

also, when plotting, I want to interpret the time in periods like: how many are below 500, how many are above 500, but below 2000 and how many are 2000 or above. so in data plotting, operTime has 3 "meanings"

so eventually, I willl need something like

select period, count(a), count(b), count(c) from table where ?whatever?

and
- period is a datetime value jumping from hour to hour
- count(a) is the number of records from one hour specified by period (for example if period is 2008/05/20 18:00:00, then from 18:00:00 to 18:59:59) which have operTime<500
- count(b) is the number of records from one hour (same as above) which have operTime in [500, 2000)
- count(c) is the number of records from one hour (same as above) which have operTime >= 2000

notes:
- I don't care much how the period is calculated, but it must be one full hour and all periods must be consecutive
- there will happen when the server is offline and hence for a specific period of time (minutes, hours or even days (god forbid)) there won't be records inserted. the query must still return hours and 0, 0, 0 as counts
- I also don't care how the intervals are constructed [0,500), [0,500], (500, 2000), (500, 2000], [500, 2000], [500, 2000), etc, etc, etc. I do care though that the 3 intervals are consecutive and no value is lost or redundant.
examples of a bad period choice:
- (0, 500] - because 0 is lost
- [0, 500] [500, 2000] (2000, inf) - because 500 is redundant (present in 2 intervals)
- [0, 500) (500, 2000) [2000, inf) - because 500 is lost

I am willing to break this up into 3 queries if one is not possible.

I am also willing to accept other suggestions on data representation as long as it fits my general purpose of displaying the 3 intervals in an aproximate one our interval.

also note that the values are examples only. I will probably decide on a 3 or 6 hour interval. so, optimization suggestions are welcome, but not necessarely needed (unless there is something obviously wrong and I seem to miss it :) )

just in case it helps, my graphic will have the date time (in hourly interval) horizontally and the operTime vertically. there will be 3 graphs, one for each count (a, b and c)

and obviously, I will not display all data, only for a designated period of time (like 30 days or 7 days starting from a specified date, midnight. just use a hardcoded value for this. I already made the calculations based on user input via date_sub and date_add). so this should offer flexibility in counting the hours as it doens't depend on the records.

thanks.Start Free Trial
 
Keywords: select count records grouped by dateti…
 
Loading Advertisement...
 
[+][-]05.20.2008 at 08:47AM PDT, ID: 21607319

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 09:58AM PDT, ID: 21608074

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 10:09AM PDT, ID: 21608159

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.20.2008 at 03:41PM PDT, ID: 21610937

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 07:38AM PDT, ID: 21615534

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 07:48AM PDT, ID: 21615669

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 10:50AM PDT, ID: 21617369

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 12:38PM PDT, ID: 21618320

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 01:23PM PDT, ID: 21618723

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 01:36PM PDT, ID: 21618828

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 02:01PM PDT, ID: 21619012

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.21.2008 at 04:24PM PDT, ID: 21619823

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: MySQL Server, SQL Query Syntax
Sign Up Now!
Solution Provided By: mukhtar2t
Participating Experts: 2
Solution Grade: A
 
 
[+][-]05.21.2008 at 11:07PM PDT, ID: 21621306

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 05:15AM PDT, ID: 21623007

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 09:47AM PDT, ID: 21625503

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 09:51AM PDT, ID: 21625539

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 11:00AM PDT, ID: 21626092

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 11:07AM PDT, ID: 21626149

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 11:13AM PDT, ID: 21626197

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]05.22.2008 at 11:53AM PDT, ID: 21626535

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_EXPERT_20070906