updatiing top values into table

C

cliff

Hi, I have the foloowing data and I have different set of rules to select
maximum numbers.
mytable is
sr cdate numvalue
1 1/11/2008 23
1 1/11/2008 35
2 1/12/2008 12
2 1/12/2008 35
3 1/13/2008 23
3 1/13/2008 34
4 1/14/2008 12
4 1/14/2008 34

I have following query to count numvalue in say previous 3 sr's

SELECT a.SR, B.NumValue, (count(a.Numvalue)/5) AS Numcount, max(b.cdate) AS
latest
FROM mytable AS a INNER JOIN mytable union AS B ON (B.SR+3>=A.SR) AND
(b.sr-a.sr<=3) AND (b.sr<a.sr)
GROUP BY a.SR, B.NumValue
ORDER BY a.SR, (count(a.Numvalue)/5) DESC , max(b.cdate) DESC , b.numvalue;

Now I select top 2 nos from above query for last sr=4 i.e., 35 & 23
Again I select top 4 nos from above query for last sr=4 ie., 35,23,34,12

Now I want to store top 2 numvalue and top 4 top numvalue in a table and
allot ruleid 1 top 2 and 2 top 4 and i want output is something like this :-

RuleID numvalue
1 35
1 23
2 35
2 23
2 34
2 12

can anyone tell me, how do I update above values automatically


thanks

cliff
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top