manipulating query result 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

all above top 2 & 4 nos will changed with new sr's say sr 5, 6 etc

Now I want manipulate above result into mytable_rules_value
automaticvally. I have set Ruleid 1 for top 2 nos and Ruleid 2 for top 4
Nos. which will remain same, but numvalue will changed depending on sr's. MY
data after manipulating above result 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 each time.


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