Simon,

On Thu, Oct 31, 2013 at 9:39 PM, Simon Slavin <slav...@bigfraud.org> wrote:
>
> On 1 Nov 2013, at 4:15am, Igor Korot <ikoro...@gmail.com> wrote:
>
>> I'm not trying to change an order of my rows.
>> Look at it this way:
>> I have a league with some teams. When the league is created the
>> players needs to be put in from the players pool. In order to assign
>> the rank inside the league I am inserting players with the rank as
>> NULL. In this case will be assigned as 1,2,3,4,etc based on the player
>> pool rank.
>> Now it is possible to insert a new player in the league. If I insert a
>> new player with the value of 0 then the same rule apply - the rank of
>> the new player will be max( rank ) + 1. Otherwise the new player will
>> be inserted by the value. So if I insert the new player with the value
>> of $5.00 and there are players with the values $0 - $5 they needs to
>> be moved in rank.
>>
>> Is it more clear now?
>
> I understood it before.  You're doing something that doesn't reflect the way 
> SQL works.  SQL is for holding your data and spitting it back out to you, not 
> for implementing your business logic.

I'm not sure I understand.
Are you saying that I don't have to populate the rank in the table on insertion?

>
> Given your description above, why try to get all the ranks right every time 
> you do an INSERT ?

Because right after insert I am displaying those records and the rank
field is the second field in the sorting algorithm.
So, on creating the league I do an insert and then do a sorting and
display all those records.

Thank you.

>  Add the player rows, and include a field with the player's value when you're 
> doing the INSERT.  If the ranks aren't used very much between changes, deduce 
> them when you need them by doing an "ORDER BY value DESC".  Or if at some 
> stage you use the rank numbers a lot, write values to a rank column just 
> before you do all the reporting and don't allow INSERTs until the reporting 
> is done.
>
> Simon.
> _______________________________________________
> sqlite-users mailing list
> sqlite-users@sqlite.org
> http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to