SELECT TOP N With Two Variables
- by Ricardo Deano
Hello all.
It's Tuesday morning and I am being thick as (I'm blaming my daughter waking up early this morning!)
I have the following example in a SQL table
Cust Group Sales
A 1 15
A 1 10
A 1 5
A 2 15
A 2 10
A 2 5
B 1 15
B 1 10
B 1 5
B 2 15
B 2 10
B 2 5
What I would like to show is the top 2 products per customer, per group sorted descending by Sales i.e.
Cust Group Sales
A 1 15
A 1 10
A 2 15
A 2 10
B 1 15
B 1 10
B 2 15
B 2 10
I'm assuming I need to declare two variables, Cust and Group, I'm just not sure how to complete this in one fell swoop.
Apologies for the thick question...no excuse. Thanks for any help.