selecting x records from table n times according to variable criteria? Hi All,
Sorry if the subject line is too obscure -- I couldn't think of a way
of describing this request.
I have a table that contains approximately 1 million records.
I want to be able to be able to select the top x records out of this
table matching variable criteria.
Pseudo table records:
custid, category, segment
1,1,1
2,1,1
3,1,1
4,1,1
5,1,2
6,1,2
7,1,2
8,1,2
9,2,1
10,2,1
11,2,1
12,2,1
13,2,2
14,2,2
15,2,2
16,2,2
17,2,3
18,2,3
19,2,3
20,2,3
So, what I'm trying to do is return a recordset, for example, that
contains the top 2 of each variation of category and segment.
ie:
1,1,1
2,1,1
5,1,2
6,1,2
9,2,1
10,2,1
13,2,2
14,2,2
17,2,3
18,2,3
The only way I can think to achieve this is in a while statement,
performing individual selects against each combination, feeding the
where criteria by variables that I automatically increment.
I can't help thinking there's a much more graceful way of achieving
this?
If anyone can give me any insight into this I'd be incredibly
appreciative!
Many thanks in advance!
Much warmth,
Murray |