| Author |
Topic |
|
coagulance
Yak Posting Veteran
78 Posts |
Posted - 2009-06-06 : 09:00:34
|
| Hi,I have the below tableJobID SeqID GroupID Contents1 1 1 Load1 2 1 CallRobot1 3 1 Pick1 4 2 Place1 5 2 CallRobot1 6 2 Load1 7 3 Unload1 8 3 Pick1 9 3 Place1 10 3 LoadWould Like to retrieve Maximum of Only 8 Rows at a time and Should select the complete GroupID In the above selection I need to getJobID SeqID GroupID Contents1 1 1 Load1 2 1 CallRobot1 3 1 Pick1 4 2 Place1 5 2 CallRobot1 6 2 Loadand NOTJobID SeqID GroupID Contents1 1 1 Load1 2 1 CallRobot1 3 1 Pick1 4 2 Place1 5 2 CallRobot1 6 2 Load1 7 3 Unload1 8 3 PickAny suggestions?Regards |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-06-06 : 09:08:28
|
| what happens when a group contains more than 8 rows? Do you want just the first 8 or complete group no matter how many or never select that group?Be One with the OptimizerTG |
 |
|
|
coagulance
Yak Posting Veteran
78 Posts |
Posted - 2009-06-06 : 09:10:15
|
| It Should always be 8 or Less and never MoreThanks, |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-06-06 : 09:21:58
|
| You didn't fully answer the question:>> Do you want just the first 8 or complete group no matter how many or never select that group?EDIT:sorry its just that your requirements conflict:-never more than 8 rows total-always the complete groupEDIT: (again) :)So in other words if groupid 1 has 9 members what should be returned?Be One with the OptimizerTG |
 |
|
|
coagulance
Yak Posting Veteran
78 Posts |
Posted - 2009-06-06 : 09:32:23
|
| It should still return only 6 Rows and the Maximum no of rows that can be retrieved is only 8 .It should be 8 or less than 8 and never more. |
 |
|
|
coagulance
Yak Posting Veteran
78 Posts |
Posted - 2009-06-06 : 11:01:11
|
| Can anyone help ? Needed urgently. |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-06-06 : 13:01:58
|
Perhaps no one is helping because you still haven't clarified the requirements.I asked: "if groupid 1 has 9 members what should be returned?"you responded: "It should still return only 6 Rows"which 6 should be returned and why not 8?Let's try it this way. Given the following data which seqIDs do you want in the result set?JobID SeqID GroupID Contents1 1 1 Load1 2 2 CallRobot1 3 2 Pick1 4 2 Place1 5 2 CallRobot1 6 2 Load1 7 2 Unload1 8 2 Pick1 9 2 something1 10 3 Place1 11 3 Load if it is 1-8 then that would violate your requirement of "Should select the complete GroupID".so should it just be seqIDs (1,10,11) ?Be One with the OptimizerTG |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-07 : 04:25:54
|
seems like what you need is thisSELECT t.*FROM YourTable tCROSS APPLY (SELECT COUNT(*) AS CummGroupCount FROM YourTable WHERE JobID=t.JobID AND GroupID<=t.GroupID) t1WHERE CummGroupCount<=8 if you want number of rows to be determined dynamically, replace hardcoded value (8) in above query with a parameter. |
 |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2009-06-07 : 08:21:59
|
In my sample data your results will only return the first row. groupid 2 will result in CummGroupCount > 8 so nothing after that will be selected including groupid 3 which only has 2 members.That may indeed be what the OP wants but I who knows - they seem to have given up their "urgent" need Be One with the OptimizerTG |
 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2009-06-07 : 13:39:34
|
quote: Originally posted by TG In my sample data your results will only return the first row. groupid 2 will result in CummGroupCount > 8 so nothing after that will be selected including groupid 3 which only has 2 members.That may indeed be what the OP wants but I who knows - they seem to have given up their "urgent" need Be One with the OptimizerTG
sorry i was not referring to your sample data. i was looking into sample data op posted and also his o/p. i think seeing the o/p what he's expecting something like mine as solution |
 |
|
|
|