Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

SQL - Assign Values based on Percentage 1

Status
Not open for further replies.

ImOutofIdeas

Technical User
Nov 22, 2010
2
US
Hi all,

I have a table (tableA) with the following columns: origin, outcome1, 1P, outcome2, and 2P. I want to update a new column (destination) with either outcome 1 or outcome 2. the columns 1P and 2P are the chances that the destination should be outcome1 or outcome2, example 70% and 30%. Any ideas on how to tackle this in an update statement? Thanks In Advance
 
If you want a random-ish outcome you could weight the result of the random number generator to give the split you need. Assuming that 1P + 2P = 100, then perhaps something like:
Code:
update tableA
  set destination = case rand() * 100 < 1P then outcome1 else outcome2 end
Not sure why 1P and 2P live in the same table as destination, though; I'd expect just one instance of those. Have I missed something?

Simon.
 
Thanks for your reply Simon that is similar to what I have done.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top