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 |
|
BStarbuck
Starting Member
4 Posts |
Posted - 2009-05-08 : 17:29:29
|
Heres my deal....The objective is to return any customer who has made more the X amount of orders. The code I used to return any customers who have made any orders isSelect fname, lname From Customer Where id In (Select Distinct Customer$id From Orders) Go My question is, how do I return duplicate Customer$id from my Orders table?Any help would be great, but a link or book reference would be awesome. |
|
|
Skorch
Constraint Violating Yak Guru
300 Posts |
Posted - 2009-05-08 : 19:18:08
|
| Try this:SELECT fname, lnameFROM Customer cRIGHT JOIN Orders o ON c.id = o.Customer$idGROUP BY fname, lnameHAVING COUNT(o.Customer$id) > XSome days you're the dog, and some days you're the fire hydrant. |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-05-09 : 04:30:23
|
quote: Originally posted by BStarbuck Heres my deal....The objective is to return any customer who has made more the X amount of orders. The code I used to return any customers who have made any orders isSelect fname, lname From Customer Where id In (Select Distinct Customer$id From Orders) Go My question is, how do I return duplicate Customer$id from my Orders table?Any help would be great, but a link or book reference would be awesome.
for returning customers who have done more than x number of orders, use belowSELECT c.*FROM Customers cINNER JOIN (SELECT CustomerID,COUNT(OrderID) AS OrderCnt FROM Orders GROUP BY CustomerID)oON o.CustomerID=c.CustomerIDWHERE o.OrderCnt > X |
 |
|
|
|
|
|