2
My question is this::
I have a table containing 25 records of people’s names. But I need to divide it into 5 groups of 5 people randomly.
Being a table 'Group A' with 5 people, another table 'Group B' with 5 people and so on.
It needs to be in SQL Server, because the data mass is much larger than this. Does anyone know how to use the function rand()
?
I put it like this:
select * from pessoas order by RAND()
But as I put, for example, to separate into groups of 5?
Is there a specific need for this to be done in SQL Server?
– Leonel Sanches da Silva
Welcome to SOPT. An interesting thing to read: http://meta.pt.stackoverflow.com/questions/699/faq-da-community . As for your question, have you tried anything? If yes, edit your question with the code you tried, it is better to help you. Another thing, why do you want to separate in other tables the data, any real reason for it or does not have something better to do with it?! What do you really need to do with the data? It may be that a select * from table order by Rand() can solve, then in loop you can separate, will already come in random order the same data.
– Marcelo Diniz
When you have any questions regarding the use of a certain command in SQL Server, just click F1 on the command that will open the SQL Server helper, where you have examples of how to use and explain every command.
– Ruberlei Cardoso