Solved

Generate histogram using SQL query based on timeseries data

Posted on 2004-09-08
3
412 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
3 Comments
 
LVL 17

Assisted Solution

by:BillAn1
BillAn1 earned 50 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 200 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

Back Up Your Microsoft Windows Server®

Back up all your Microsoft Windows Server – on-premises, in remote locations, in private and hybrid clouds. Your entire Windows Server will be backed up in one easy step with patented, block-level disk imaging. We achieve RTOs (recovery time objectives) as low as 15 seconds.

Question has a verified solution.

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

Suggested Solutions

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
This article shows gives you an overview on SQL Server 2016 row level security. You will also get to know the usages of row-level-security and how it works
Via a live example combined with referencing Books Online, show some of the information that can be extracted from the Catalog Views in SQL Server.
Via a live example, show how to backup a database, simulate a failure backup the tail of the database transaction log and perform the restore.

829 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