Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 simple group by

Author  Topic 

Ex
Posting Yak Master

166 Posts

Posted - 2005-01-19 : 19:54:02
hey all i know this is such a easy question
but just having a mental blank

i have a table like so


date time flow
1/1 1:30 5
1/1 1:45 10
1/1 2:00 4
1/1 2:15 8
1/1 2:30 12
etc etc etc

and i want to do a normal SELECT sql query(if possible)


grouping by date then hour

like so

and would return
date time flow
1/1....1.....7.5
1/1....2...... 8


i would like this query to go over serveral databases if this is possible great if TSQL is required then no worries

thanks

nr
SQLTeam MVY

12543 Posts

Posted - 2005-01-19 : 20:13:08
select date, time = datepart(hh,time), flow = avg(flow)
from tbl
group by date, datepart(hh,time)
order by date, datepart(hh,time)


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -