|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
|||
|
|||
|
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. |
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > help with weird query statement |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|
|
|