mysql如何按权重查询数据啊?
怪我咯
怪我咯 2017-04-17 16:43:36
0
3
807

假设表a有一个字段b,b存的是权重,范围0-100吧,我想随机查一条记录,但是按权重给出数据,该如何写呢

怪我咯
怪我咯

走同样的路,发现不同的人生

reply all(3)
巴扎黑

select * from a order by b desc

The front of the returned result set has a higher weight
For example

--------------
|b  | 其余字段|
--------------
|100| xxxxxxx|
--------------
|97| xxxxxxx|
--------------
|6 | xxxxxxx|
--------------
|5 | xxxxxxx|
-------------
阿神

If you don’t have much dataselect *from a order by rand() limit 1

Ty80

How can you sort if you only fetch one piece of data... Just randomly fetch one piece and that's it. Upstairs, if you need to fetch multiple pieces, you need to sort them with one layer of sql. select * from (select * from a order by rand() limit n) aa order by b desc;

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template