SunQuest
           Database Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsOther TechnologiesDatabase Help

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 Codewalkers Forums Sponsor:
Stay one step ahead of the competition. Evaluate and give feedback on some of the hottest web development tools on the market today. Make your opinion heard! Click Here
  #1  
Old June 2nd, 2003, 08:24 PM
BubbaBelly BubbaBelly is offline
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Apr 2007
Posts: 7 BubbaBelly User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
help with weird query statement

Hello,
I have some data I need to query. I have tables with the fields: YEAR, MONTH, data1, data2, etc...

What I do, is that I specify a yearly range, say 2000 - 2002. I have data for each month, within each year. So what I want to do is total the data for each year individually. So the output would be 3 separate rows, in this case, one for each year. I can easily total for all years or display individual months, but I can't seem to total the years individually. I'm using mysql, any help is much appreciated. I know that I can do this within a loop and query each year at a time, but I want to be able to do this in one sql statement. Thanks in advance...
Bubba

Reply With Quote
  #2  
Old June 2nd, 2003, 10:09 PM
Blindeddie Blindeddie is offline
Codewalkers Regular (2000 - 2499 posts)
 
Join Date: Apr 2007
Location: NJ - USA
Posts: 2,152 Blindeddie User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 4
RE: help with weird query statement

You could use the SUM() and group by functions
for example:

select year, sum(data1) as data1_total from my_table group by year

you could also break down the counts down by year and month with the following:

select year,month, sum(data1) as data1_total from my_table group by year,month

you can use the sum function on all the other data rows in the table as well.

Reply With Quote
Reply

Viewing: Codewalkers ForumsOther TechnologiesDatabase Help > help with weird query statement


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


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





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