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 |
|
pyrrhus_finch
Yak Posting Veteran
51 Posts |
Posted - 2005-01-25 : 19:05:47
|
| Please help, I'm stumped as to how to write these querys.Crude Example DataCustomerID|Purchase1.........|ice cream2.........|ice cream3.........|cake1.........|cake1.........|cake 3.........|cake2.........|ice creamI need to know the following# Customers who bought only ice cream:# Customers who bought only cake:# Customers who bought Ice cream and bought cake too:How would I write this Query?I haven't the fiantest idea.Thanks very much. |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2005-01-25 : 19:21:47
|
| SELECT CustomerID, CASE WHEN Min(Purchase)=Max(Purchase) THEN Max(Purchase) + ' only' ELSE 'Both' ENDFROM myTableGROUP BY CustomerID |
 |
|
|
pyrrhus_finch
Yak Posting Veteran
51 Posts |
Posted - 2005-01-25 : 20:08:21
|
| Ugh. I didn't mention I was using Access - keep forgetting its so different. Any idea how to write this in Access? thanks |
 |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2005-01-25 : 20:34:03
|
Well, it's easier if you post Access questions in the MS Access forum, and (especially) NOT in the Transact-SQL forum. SELECT CustomerID, Iif(Max(Purchase)=Min(Purchase), Max(Purchase) & " only", "Both") AS PurchFROM myTableGROUP BY CustomerID |
 |
|
|
pyrrhus_finch
Yak Posting Veteran
51 Posts |
Posted - 2005-01-26 : 12:17:37
|
| Hey thanks a ton! Learned something really usefull today of SQL and AccessQL.. ha! Really, thanks again! Your the Bomb! |
 |
|
|
|
|
|