Solved

Generate histogram using SQL query based on timeseries data

Posted on 2004-09-08
3
425 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 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

Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

Question has a verified solution.

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

Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
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
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Via a live example, show how to shrink a transaction log file down to a reasonable size.

696 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