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.
| Author |
Topic |
|
sg2255551
Constraint Violating Yak Guru
274 Posts |
Posted - 2011-04-14 : 10:03:03
|
| hiThis is my tableDate ClientID Amount11/04 1 $1011/04 1 $511/04 2 $1511/04 3 $511/04 4 $211/04 5 $1012/04 1 $312/04 2 $512/04 2 $1012/04 3 $512/04 3 $512/04 5 $10I would like to count number of clients based on the amount spent for any given day. For example, i want to find out how many client spent on a given of more than or equal to $10 between 11/04 to 12/04The result should look like thisDate Count11/04 3 12/04 3How should i go about this? Thanks |
|
|
singularity
Posting Yak Master
153 Posts |
Posted - 2011-04-14 : 10:14:27
|
| [code]select Date, count(ClientID) as [Count]from(select Date, ClientID, sum(Amount) as Amountfrom yourtablewhere Date between '11/04/2011' and '12/04/2011'group by Date, ClientIDhaving sum(Amount) >= 10) agroup by Date[/code] |
 |
|
|
mmarovic
Aged Yak Warrior
518 Posts |
Posted - 2011-04-14 : 13:04:49
|
| The sum(amount) can be omitted from column list in subquery.MirkoMy blog: http://mirko-marovic-eng.blogspot.com/ |
 |
|
|
|
|
|