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
 General SQL Server Forums
 New to SQL Server Programming
 get sum of column values on an interval

Author  Topic 

abhid
Starting Member

2 Posts

Posted - 2015-03-01 : 05:49:26
Hi All,

I am new to this group and to Sql query also. My requirement is the following

I have a table with these values...

cola colb colc cold
16:01 1 2 3
17:01 1 3 4
18:01 5 6 8
16:01 8 2 1
17:01 9 5 1
18:01 3 5 1
16:01 4 6 1
17:01 2 3 5
18:01 8 4 3

Now I want to get the SUM of colb, colc on each interval betweeen 16:01 to 18:01...

Can anyone please help me with this problem

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-03-01 : 06:48:19
select sum(colb), sum(colc), sum(cold)
from table
where cola >= '16:01" and cola <= '18:01'
Go to Top of Page

abhid
Starting Member

2 Posts

Posted - 2015-03-01 : 07:07:24
thanks for the answer...but this query will return only 1 resultset...here I have 3 different interval between 16:01 to 18:01, so I need 3 resultsets
Go to Top of Page

gbritton
Master Smack Fu Yak Hacker

2780 Posts

Posted - 2015-03-01 : 08:32:26
select sum(colb), sum(colc), sum(cold)
from table
Group bt cola
Go to Top of Page

huangchen
Starting Member

37 Posts

Posted - 2015-04-02 : 05:58:01
unspammed
Go to Top of Page
   

- Advertisement -