473,387 Members | 1,528 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Question: Selecting random records from the db (puzzle of the day)

I am interested to hear your suggestions on this...

I have a table full of survey questions. The questions are individually
classified as priority 1, 2 or 3. (Priority 1 means the question shows up 3
times as much as the others, priority 2 means it shows up 2 times as much as
priority 1.)

I want to fill a temp table with a random selection of these questions.
Example: If I want the temp table to contain 100 random "question" records
then 1/6 of the questions would be priority 1, 1/3 would be priority 2 and
1/2 would be priority 3. Any suggestions/ideas how to do this?

Thanks!
Nov 18 '05 #1
2 1362
you can try something like this for each priority to push into the temp
table

select top 50 * from survey where priority = 3 order by NEWID()

order by NEWID() --> randomly fetches records for priority 3
Prathap

"VB Programmer" <Do*****************@jEmail.com> wrote in message
news:e5**************@TK2MSFTNGP09.phx.gbl...
I am interested to hear your suggestions on this...

I have a table full of survey questions. The questions are individually
classified as priority 1, 2 or 3. (Priority 1 means the question shows up 3 times as much as the others, priority 2 means it shows up 2 times as much as priority 1.)

I want to fill a temp table with a random selection of these questions.
Example: If I want the temp table to contain 100 random "question" records then 1/6 of the questions would be priority 1, 1/3 would be priority 2 and
1/2 would be priority 3. Any suggestions/ideas how to do this?

Thanks!

Nov 18 '05 #2
http://www.sqlteam.com/item.asp?ItemID=8747 - if you're using Windows 2000
or higher
http://www.sqlteam.com/item.asp?ItemID=896 - otherwise

Alan

"VB Programmer" <Do*****************@jEmail.com> wrote in message
news:e5**************@TK2MSFTNGP09.phx.gbl...
I am interested to hear your suggestions on this...

I have a table full of survey questions. The questions are individually
classified as priority 1, 2 or 3. (Priority 1 means the question shows up
3 times as much as the others, priority 2 means it shows up 2 times as
much as priority 1.)

I want to fill a temp table with a random selection of these questions.
Example: If I want the temp table to contain 100 random "question"
records then 1/6 of the questions would be priority 1, 1/3 would be
priority 2 and 1/2 would be priority 3. Any suggestions/ideas how to do
this?

Thanks!

Nov 18 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Jason | last post by:
Hi, I have a few million data items being received by my program and I wish to store them in a list, with each item being inserted in any position in the list. Any performance tips so that my...
12
by: Joseph Shraibman | last post by:
Is there a way to get random rows besides ORDER BY random()? The problem with ORDER BY random() is that is has to get all the rows from the table before the results are returned. ...
11
by: NC Tim | last post by:
Hello, I think the question i have is fairly straightforward, but I can't seem to replicate the old SAS frequency procedure when I try to accomplish this in MS Access. anyway, i have about 10...
4
by: yf | last post by:
A KB article "http://support.microsoft.com/default.aspx?scid=kb;en-us;209599" tells that the maximum number of records that a table may hold if the PRIMARY key data type is set to AUTONUMBER is...
3
by: John Fairhurst | last post by:
Hi, The following code should select the specified number of records randomly from the database <% .... query = "SELECT FROM " Set RS = Server.CreateObject("ADODB.Recordset")
3
by: Cindy | last post by:
I'm trying to use the NEWID function in dynamic SQL and get an error message Incorrect syntax near the keyword 'ORDER'. Looks like I can't do an insert with an Order by clause. Here's the code:...
5
by: megahurtz | last post by:
I need to put together an SQL statement and I can't think of how to make it work properly. The scenario is that I have news items in a database that have a launch time and can optionally have an...
2
by: megahurtz | last post by:
I need to put together an SQL statement and I can't think of how to make it work properly. The scenario is that I have news items in a database that have a launch time and can optionally have an...
4
by: honey777 | last post by:
Problem: 15 Puzzle This is a common puzzle with a 4x4 playing space with 15 tiles, numbered 1 through 15. One "spot" is always left blank. Here is an example of the puzzle: The goal is to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.