Answer the question
In order to leave comments, you need to log in
How to split a table with users by teams several times?
There is an entity users
Let's say there are 100 users in this stage field command = null.
Under certain conditions, it is necessary to update the rows so that the user with the lowest points becomes the same number in the team as the user with the highest points , and so on for each of the next points in descending order . In the end, it turns out 50 teams of 2 people. How is it easier to do this, write logic on node and do udpate on each line, or can it be done using postgre?
Next, you need to do the same, only teams are combined instead of people. That is, from 1 team, where 2 people, you get one team with 4 people in it.
Answer the question
In order to leave comments, you need to log in
I did not understand the meaning of the number in points, but I believe that it is just random)
In this case, it seems like this:
This command will sort all users by points in ascending order, and add a sequential number to them so that the user with row_number = 1 will have the lowest points and the highest row_number will have the highest.
Thanks to the serial key, we can easily make pairs in a cycle:
for i in range ({число юзеров}/2)
USER (row_number = i) <-> USER (row_number = 100 - i)
Since points
it is not unique, the grouping will be random. And it can't be done with a single request.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question