Professional Web Applications Themes

Weird results - MySQL

Hello, I am having a table with an integer column which I use for probability calculations (the higher a value the more often it is chosen). Now I am having the following query, which should actually incorporate these probabilities, however it seems to prefer values from the middle range SELECT * FROM table WHERE field>=(SELECT RAND()*MAX(field) FROM table) ORDER BY field LIMIT 1 If I split it up it still seems to prefer mid-range values over values closer to the higher end, however it doesnt "completely" ignore the highest value anymore. random_value = SELECT RAND()*MAX(field) FROM table; SELECT * FROM ...

  1. #1

    Default Weird results


    Hello,

    I am having a table with an integer column which I use for probability
    calculations (the higher a value the more often it is chosen).

    Now I am having the following query, which should actually incorporate
    these probabilities, however it seems to prefer values from the middle range

    SELECT * FROM table WHERE field>=(SELECT RAND()*MAX(field) FROM
    table) ORDER BY field LIMIT 1

    If I split it up it still seems to prefer mid-range values over values
    closer to the higher end, however it doesnt "completely" ignore the
    highest value anymore.

    random_value = SELECT RAND()*MAX(field) FROM table;
    SELECT * FROM table WHERE field>=random_value ORDER BY field LIMIT 1

    Does anyone have an explanation for that or a better solution? Thanks
    Alexander Mueller Guest

  2. #2

    Default Re: Weird results

    "Alexander Mueller" <noneexample.com> wrote in message
    news:43f9d935$0$47965$892e7fe2authen.yellow.readf reenews.net...
    > random_value = SELECT RAND()*MAX(field) FROM table;
    > SELECT * FROM table WHERE field>=random_value ORDER BY field LIMIT 1
    >
    > Does anyone have an explanation for that or a better solution? Thanks
    See the discussion of FLOOR(i + RAND() * (j - i + 1)) in this page:
    [url]http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html[/url]

    random_value = SELECT FLOOR(1+RAND()*MAX(field)) FROM table;
    SELECT * FROM table WHERE field>=random_value ORDER BY field LIMIT 1

    Regards,
    Bill K.


    Bill Karwin Guest

  3. #3

    Default Re: Weird results

    Bill Karwin wrote:
    >
    > See the discussion of FLOOR(i + RAND() * (j - i + 1)) in this page:
    > [url]http://dev.mysql.com/doc/refman/5.0/en/mathematical-functions.html[/url]
    >
    > random_value = SELECT FLOOR(1+RAND()*MAX(field)) FROM table;
    > SELECT * FROM table WHERE field>=random_value ORDER BY field LIMIT 1
    >
    > Regards,
    > Bill K.
    Thanks Bill, but I dont really see the connection to my posting. I do
    not have problems with the query you mentioned.
    Alexander Mueller Guest

Similar Threads

  1. FLV Issue...and it's weird weird weird
    By boxdoctor in forum Macromedia Flash Flashcom
    Replies: 2
    Last Post: June 8th, 05:54 PM
  2. Complex join = no results (for a query that shouldreturn results)
    By jchapman16 in forum Coldfusion Database Access
    Replies: 4
    Last Post: August 23rd, 10:49 PM
  3. Query results don't display properly in results table.IGNORE PREVIOUS
    By JoyRose in forum Coldfusion - Advanced Techniques
    Replies: 1
    Last Post: March 24th, 07:28 PM
  4. weird results on XP with WAMP5
    By paul8 in forum Macromedia Flash Data Integration
    Replies: 0
    Last Post: March 2nd, 11:39 PM
  5. weird results after publish
    By Jordan in forum Macromedia Flash
    Replies: 0
    Last Post: June 28th, 05:27 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139