Professional Web Applications Themes

relevancy - MySQL

Is there any way for MySQL to give relevancy to a query based on an integer? I have a field that can have values from 1 to 256, I want to look for records similar to "50", in other words everything < 60 and > 40. But I want to rank them so that 49 and 51 appear before 41 and 59. Can MySQL do that, if not what's the fastest way to do something like that? THanks, SS...

  1. #1

    Default relevancy

    Is there any way for MySQL to give relevancy to a query based on an
    integer? I have a field that can have values from 1 to 256, I want to
    look for records similar to "50", in other words everything < 60 and >
    40. But I want to rank them so that 49 and 51 appear before 41 and 59.
    Can MySQL do that, if not what's the fastest way to do something like
    that? THanks,

    SS

    schwarzenschafe@gmail.com Guest

  2. #2

    Default Re: relevancy

    com <com> schrieb: 

    Just ORDER BY (ABS(50-integer)) ASC.

    That should put 49 and 51 next to each other, since |50-49| is 1 and
    |51-50| is 1 as well.

    HTH,
    --
    Philipp Tölke
    PGP: 0x96A1FE7A
    Philipp Guest

  3. #3

    Default Re: relevancy

    Philipp Tölke wrote: 

    Thanks... I hate it when I can't see the simple solutions because I'm
    looking for a complicated one.

    SS

    schwarzenschafe@gmail.com Guest

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