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 2008 Forums
 Transact-SQL (2008)
 Sum with Having

Author  Topic 

a_Qaddomi
Starting Member

6 Posts

Posted - 2011-11-20 : 06:22:09
Hi there ,I have a question table contains

QuiestionID QuestionText EstimatedTime
----------- ------------ -------------
1------------------A-------------5
2------------------B-------------4
3------------------C-------------6
4------------------D-------------3

I need a select statement retrieve random questions with estimated time 9 for example. I tried this statement but it is not working ..

select QuestionID,sum(EstimatedTime) from question group by QuestionID having sum(EstimatedTime)=9.

Thanks for your time

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-20 : 06:28:00
[code]select top 10 * from table where EstimatedTime=9 order by newid() [/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

a_Qaddomi
Starting Member

6 Posts

Posted - 2011-11-20 : 06:31:03
No I need sum of estimated time of retrieved questions is 9 .. so you need to use the SUM function.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-11-20 : 06:32:46
quote:
Originally posted by a_Qaddomi

No I need sum of estimated time of retrieved questions is 9 .. so you need to use the SUM function.


hmm? what does that mean? so can you show what would be output from data above?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

a_Qaddomi
Starting Member

6 Posts

Posted - 2011-11-20 : 06:35:28
ok .. the result would be for example QuestionID -->1 & 2 OR 3 & 4 because sum of this questions' estimated time is 9
Go to Top of Page

a_Qaddomi
Starting Member

6 Posts

Posted - 2011-11-20 : 10:15:02
No Body can help ??
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2011-11-21 : 03:13:30
This will get you some idea
http://weblogs.sqlteam.com/peterl/archive/2008/11/26/Finding-streaks-in-data.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -