?
Solved

Generate histogram using SQL query based on timeseries data

Posted on 2004-09-08
3
Medium Priority
?
432 Views
Last Modified: 2008-03-17
I would like to generate a histogram based on a set of time series data stored in SQL server.  For example I have lots of rows of data stamped with a date and time and want to create 24 classes to put the data in.  Is there a way that I can do this with a SQL query rather than writing an external program?  The BOL has a topic listed under "histogram chart" but I don't think that applies to what I am talking about.
0
Comment
Question by:stealth188
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 17

Assisted Solution

by:BillAn1
BillAn1 earned 200 total points
ID: 12011466
You can do it with a case statement,

e.g.
     SELECT bucket, count(*) from (
               SELECT
                   case when DateStamp < '2001-01-01' then 'bucket1'
                           when DateStamp between '2001-01-01' and '2002-01-01' then 'bucket2'
                           when DateStamp between '2002-01-01' and '2003-01-01' then 'bucket3'
                           ...
                  end as bucket
                FROM MyTable ) inr
              group by bucket

0
 
LVL 12

Accepted Solution

by:
kselvia earned 800 total points
ID: 12012221
Perhaps see this posting for a similar question and solution:

http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20999291.html
0
 
LVL 1

Author Comment

by:stealth188
ID: 12017300
Thank you both for your input.  I'll be working with this today and let you know how it works out.  Thanks!
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

What if you have to shut down the entire Citrix infrastructure for hardware maintenance, software upgrades or "the unknown"? I developed this plan for "the unknown" and hope that it helps you as well. This article explains how to properly shut down …
Windocks is an independent port of Docker's open source to Windows.   This article introduces the use of SQL Server in containers, with integrated support of SQL Server database cloning.
Via a live example, show how to set up a backup for SQL Server using a Maintenance Plan and how to schedule the job into SQL Server Agent.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

650 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question