On Monday, March 24, 2014 10:52:20 AM UTC-4, afancy wrote:
Hi,
I have a table data , and sorted by Id1`value. Now I want to select Top-k records (e.g., k=2) in each group. How could I select? thanks!
q)data
id1 id2 value
1 2 0.5
1 3 0.6
1 4 0.1
2 1 0.3
2 3 0.32
2 5 0.42
q)id1value xdesc data
id1 id2 value
2 5 0.42
2 3 0.32
2 1 0.3
1 3 0.6
1 2 0.5
1 4 0.1
The group is based on the values of id1. In this case, there are two groups, group one with id1=1, and group two with id1=2. I want to return top-k records in each group. In this example, if k=2, the result that I want is:
On Monday, March 24, 2014 10:52:20 AM UTC-4, afancy wrote:<o:p></o:p>
Hi, <o:p></o:p>
<o:p> </o:p>
I have a table data , and sorted by Id1`value. Now I want to select Top-k records (e.g., k=2) in each group. How could I select? thanks!<o:p></o:p>
<o:p> </o:p>
q)data<o:p></o:p>
id1 id2 value<o:p></o:p>
--------------------------<o:p></o:p>
1 2 0.5 <o:p></o:p>
1 3 0.6 <o:p></o:p>
1 4 0.1 <o:p></o:p>
2 1 0.3 <o:p></o:p>
2 3 0.32 <o:p></o:p>
2 5 0.42 <o:p></o:p>
<o:p> </o:p>
q)id1value xdesc data<o:p></o:p>
id1 id2 value<o:p></o:p>
--------------------------<o:p></o:p>
2 5 0.42 <o:p></o:p>
2 3 0.32 <o:p></o:p>
2 1 0.3 <o:p></o:p>
1 3 0.6 <o:p></o:p>
1 2 0.5 <o:p></o:p>
1 4 0.1 <o:p></o:p>
<o:p> </o:p>
<o:p> </o:p>
The group is based on the values of id1. In this case, there are two groups, group one with id1=1, and group two with id1=2. I want to return top-k records in each group. In this example, if k=2, the result that I want is:<o:p></o:p>