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 2005 Forums
 Transact-SQL (2005)
 Getting top 5 with a group statement

Author  Topic 

Amaranthix
Starting Member

7 Posts

Posted - 2008-09-18 : 09:31:15
Hi, this is my first time posting here and this is probably a very newbie question, but I've only been writing SQL for about a year and am self-taught.

I'm using SQL Server 2005 and have 2 tables:

CustomerTable C (CustomerID is the PK)
TransactionTable T (TransactionID is the PK)

I created a table (master) joining these two with all records and the following fields using a specific date range and some suppression flags:

CustomerID, StoreID, Purchase_Date, Cashier_Number, TransactionID

For what I'm trying to do I need the TOP 5 TransactionIDs by Purchase_Date, by StoreID, CustomerID, by Cashier_Number.

So essentially I'm trying to create this:

CustomerID TransactionID
1 1
1 2
1 3
1 4
1 5
2 6
2 7
2 8
2 9
2 10

If you need any additional information let me know, I'll be checking the forums today and trying to figure this out on my own.

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-18 : 09:36:20
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/09/12/return-top-n-rows.aspx

Madhivanan

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

Amaranthix
Starting Member

7 Posts

Posted - 2008-09-18 : 09:44:13
This looks like exactly what I need, thank you very, very much.
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2008-09-18 : 09:49:46
quote:
Originally posted by Amaranthix

This looks like exactly what I need, thank you very, very much.


You are welcome

Madhivanan

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

- Advertisement -