I have tables with more than 1 million records and I want to select random rows from this table, but in all No record - Only select random rows from the results that match some conditions.
The display is very important , so I can not use the order by NEWID and then select the first item.
The table structure is something like this:
ID start title nVARCHAR (100) level INT point INT
Now, I Written like a question:
asas tmp_one (as select ryid from the reed [user] as u becomes involved in inner [item] because r But RUserID = UID where (@manelwell and @maxLevel) about [level] and (ABS (BINARY_CHECKSUM (NEWID), RID, Nude ()))% 10000/100 ) & Gt; @RangeOne), tmp_two as (Where is tmp_one from RID as T tmp_one.RID ((ABS (BINARY_CHECKSUM (NID), RID, NIID ()))% 10000) / 100) @RangeTwo), select tmp_three as RID as RID (where tmp_two where ((ABIN (BINARY_CHECKSUM (NEWID), NEWID ())))% 10000) / 100) & lt; @RangeThree) Select the tmp_three from the top 10 rid
I tried to randomly select 10 items, and then select one of them, but I have a wonderful problem !!!
Occasionally the output is sorted by item level! And I do not want this (it's not really random). I really do not know how the results of the level were given.
Please suggest some solution that helps me to select random records in high performance and there is no random duplication selected in higher iteration.
Depending on the MSDN, instead of the one you save:
< Code> Select the top 10 * This name indicates:Select the top 10 from the table where the int (int (binary_checks (*) * rand ()) ))% 100) & lt; 10
There is very little logical to read a better performance.
Comments
Post a Comment