2

for a table on ms-sql2000 containing the following columns and numbers:

S_idJ_id    Se_id   B_id    Status  Count   multiply
63  1000    16  12  1   10  2       
64  1001    12  16  1   9   3       
65  1002    17  12  1   10  2       
66  1003    16  12  1   6   3       
67  1004    12  16  1   10  2       

I want to generate an classic asp script which will do the following for each row where status=1 :

-multiply -> answer= multiply column 'count' with column 'multiply'

Then:

count the total answer and sum for each se_id like :

se_id   total
12      47
16      38
17      20

and display on screen like

Rank    se_id   total
1       12      47
2       16      38
3       17      20

Condition: if there are multiple equal total values then give the lower numbered se_id a priority for getting a ranking and give the next higher numbered se_id the next number in rank

Any sample code in classic asp or advice is welcome on how to get this accomplished

Joel Coehoorn
  • 399,467
  • 113
  • 570
  • 794
hhead
  • 31
  • 6

1 Answers1

0

'score' = source table.

if (EXISTS (select * from INFORMATION_SCHEMA.TABLES where TABLE_NAME = 'result_table')) 
begin
  drop table result_table;
end

select 
  rank = IDENTITY(INT,1,1), 
  se_id, sum(multiply * count) as total
into result_table
from score
where status = 1
group by se_id
order by total desc, se_id;

[Edit] Change query as answer on first comment

Arjen van der Spek
  • 2,630
  • 16
  • 20