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 |
|
spost
Starting Member
2 Posts |
Posted - 2008-05-05 : 11:11:34
|
| I'm having trust issue with my HAVING clause.I'm trying to find customers who have spent X (in this case 500 or more) dollars in a month--photogs spending $500 or more on products in April, 2008SELECT PhotogCode, SUM(ProductRevenue)FROM TBL_Reporting_DailySalesRevenueAndProductUseBy_PhotogWHERE DATEPART(MM, [Date]) = 4AND DATEPART(YY, [Date]) = 2008GROUP BY PhotogCodeHAVING SUM(ProductRevenue) >= 500However, I'm finding that if I use a variation of this (see below)--all photogs spending money on products in April, 2008 ordered by totalSELECT PhotogCode, SUM(ProductRevenue)FROM TBL_Reporting_DailySalesRevenueAndProductUseBy_PhotogWHERE DATEPART(MM, [Date]) = 4AND DATEPART(YY, [Date]) = 2008GROUP BY PhotogCodeORDER BY SUM(ProductRevenue) DESCand I look at the returned rows, I'm discovering that there are an additional 12 customers who have spent $500 or more...is there something I'm missing with the query using HAVING?Thanks, Steph |
|
|
spost
Starting Member
2 Posts |
Posted - 2008-05-05 : 11:21:57
|
| Hmm...and it seems that since posting this, I'm now getting all the rows I'm looking for. Figures, huh? |
 |
|
|
|
|
|
|
|