Good day. There is such a table:

word TEXT, par1 INEGER, par2 INEGER, par3 INEGER 

It is necessary to set the parameter par3 based on the first parameter (par1). Example:

  word par1 par2 par3 'someword' 100 0.25 3 'someword1' 200 0.50 2 'someword3' 400 0.25 1 

That is, it turns out that the 3rd parameter is a kind of rating that will be based on the first parameter. The entry with the maximum value of par1 will correspond to the value number 1, and so on. The table now has about ~ 17k records, and here you need to set this third parameter in some way.

  • and by what formula is par3 calculated? - Crystal
  • It is necessary to sort the table by descending par1 and fill in the field with consecutive numbers. I can do current for mysql - splash58
  • @Crystal is a rank or rating. The first place is given to the lines with the maximum values ​​of par1 etc. .. I have questions to the author: is the table updated? Is it possible to remake the table schema? - Sanek Zhitnik
  • By the first parameter. Let us have three entries in the table, they have par1 of 10. 15. 14 , respectively, par3 will be 3, 1, 2 . The maximum value of par1 in the table will be equal to number 1, and so on ... - zeronight
  • @Sanek Zhitnik, Yes, the table is updated. And yes, there is an opportunity to remake the scheme. - zeronight

1 answer 1

I don’t know if there is a PRIMARY KEY in your table, so I added it myself. The request will be as follows:

 drop table if exists Table1; create table Table1 ( id integer primary key, word text, par1 integer, par2 float, par3 integer ); insert into Table1 select 1, 'someword', 100, 0.25, null; insert into Table1 select 2, 'someword1', 200, 0.50, null; insert into Table1 select 3, 'someword3', 400, 0.25, null; insert into Table1 select 4, 'someword4', 300, 0.25, null; drop table if exists temp.TmpTable; create temp table TmpTable ( id integer, word text, par1 integer, par2 float, par3 integer ); insert into temp.TmpTable select id, word, par1, par2, par3 from Table1 order by par1 desc; update Table1 set par3 = (select tmp.ROWID from temp.TmpTable tmp where tmp.id = Table1.id); select * from Table1 order by par3 RecNo id word par1 par2 par3 ----- -- --------- ---- ---- ---- 1 3 someword3 400 0.25 1 2 4 someword4 300 0.25 2 3 2 someword1 200 0.5 3 4 1 someword 100 0.25 4