SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Iron Speed
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
Free Web 2.0 Code Generator! Generate data entry and reporting .NET Web apps in minutes. Quickly create visually stunning, feature-rich apps that are easy to customize and ready to deploy. Download Now!
  #1  
Old March 30th, 2007, 02:35 AM
ole_lukoe ole_lukoe is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 2 ole_lukoe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 15 sec
Reputation Power: 0
"histogram" in sql

hello, i am pretty new to sql. i can't figure out how, given a table of a quantity obtained in many identical experiments, create a table whose data can then be used directly to plot a histogram of the results. in other words, this new table should tell me how many times the quantity was between, say, 0 and 10, 10 and 20, 20 and 30 etc.

Reply With Quote
  #2  
Old March 30th, 2007, 11:05 AM
Lauramc's Avatar
Lauramc Lauramc is offline
SQL Slarentice
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: In My Happy Place
Posts: 1,779 Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 15 h 29 sec
Reputation Power: 1037
Well you might just have a table that contains the results with an experiment_id and a count. When you get the data out to make a chart you can use the query criteria to get counts in various ranges.

If you have different things you need to keep counts for, just create a new column for each type of thing.

Does that help? Do you have a table designed already? What program or tools do you plan to use to plot your histogram?

Reply With Quote
  #3  
Old March 30th, 2007, 05:39 PM
ole_lukoe ole_lukoe is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2007
Posts: 2 ole_lukoe User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 20 m 15 sec
Reputation Power: 0
i think i didn't phrase my question very well. let's say i have a table like this:

num value
1 5
2 11
3 6
4 25
5 24
6 29
7 38
8 17
9 15
10 11


the resulting table should look like this:

range count
0-10 2
10-20 4
20-30 3
30-49 1

what query can i use to create the second table from the first?

Reply With Quote
  #4  
Old April 2nd, 2007, 10:57 AM
Lauramc's Avatar
Lauramc Lauramc is offline
SQL Slarentice
ASP Free Intermediate (1500 - 1999 posts)
 
Join Date: Nov 2004
Location: In My Happy Place
Posts: 1,779 Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level)Lauramc User rank is General 1st Grade (Above 100000 Reputation Level) 
Time spent in forums: 2 Weeks 1 Day 15 h 29 sec
Reputation Power: 1037
You would have to do a series of nested queries to get the data in one select statement (or you can create a new table, then update). It would be something like this:

Code:
SELECT
    [0_to_10] = (SELECT COUNT(myTable.value) FROM myTable WHERE value Between 0 and 10)
    [11_to_20] = (SELECT COUNT(myTable.value) FROM myTable WHERE value Between 11 and 20)
    [20_to_30] = (SELECT COUNT(myTable.value) FROM myTable WHERE value Between 21 and 30)

Reply With Quote
  #5  
Old April 2nd, 2007, 02:42 PM
dbickin dbickin is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jun 2004
Location: New Jersey, USA
Posts: 360 dbickin User rank is Private First Class (20 - 50 Reputation Level)dbickin User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 3 Days 21 h 56 m
Reputation Power: 4
How about trying:
select case value/10
when <1 then ' 0 to 10'
when <2 then '11 to 20'
when <3 then '21 to 30'
when <5 then '31 to 49' end as range, count(value)...

(Note, I didn't test it, so hopefully I didn't hopelessly mangle the case...when...then syntax. But you should get the idea.)

David

Reply With Quote
  #6  
Old April 8th, 2008, 07:44 PM
dazlari dazlari is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2008
Posts: 1 dazlari User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 9 m 37 sec
Reputation Power: 0
simple histogram solution

Late I know but this may help others looking to achieve this goal.

You have an array of sample statistics and you want to break them into groups of an arbitrary size. Then you want a count of the number in each group.

Using the modulus function (remainder after division) in SQL you can determine the start value of each group as:

value - mod(value, group_size)

Then you only need count(*) them and group by them.

select value-mod(value,500), count(*)
from MyFile
where My_Selection_Criteria_is_true
group by value-mod(value,500)


This produced a result in my case like:


Numeric Expression COUNT ( * )
0 480
500 290
1,000 134
1,500 247
2,000 268
2,500 287
3,000 259
3,500 230
4,000 232
4,500 221


Hope this helps!
Daz.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > "histogram" in sql


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

 Free IT White Papers!
 
Accelerating Trading Partner Performance
One in five. That's how many partner transactions have at least one error. That is an amazing statistic, particularly given the extraordinary leaps in innovation across the global supply chain during the past two decades. Download this white paper to learn more.

 
Competing on Analytics
This Tech Analysis is designed to help identify characteristics shared by analytics competitors, and includes information about 32 organizations that have made a commitment to quantitative, fact-based analysis.

 
Cost Effective Scaling with Virtualization and Coyote Point Systems
An overview of the industry trend toward virtualization, how server consolidation has increased the importance of application uptime and the steps being taken to integrate load balancing technology with virtualized servers.

 
Five Checkpoints to Implementing IP Telephony
Implementation planning for IP PBX software and IP telephony has become vital as businesses replace discontinued legacy PBX phone systems. This informative whitepaper outlines five "checkpoints" for any implementation plan that will help make IP communications a successful proposition.

 
Hosted Email Security: Staying Ahead of New Threats
In the last two years, email has become a fierce battleground between the nefarious forces of spam and malware, and the heroes of messaging protection. The spam volumes increased alarmingly every month, bringing clever new forms of phishing and virus propagation attacks.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 4 hosted by Hostway