downloadTemp2014 2016-04-08 17:45
浏览 24

反加权随机选择

I have a Mysql database table with ~10000 songs. One column is the last time they've been played. I want to randomly select a song, giving more weight to the least played songs. It should be a fast query, so maybe we don't need to count the number of times a song's been played and just use the 'last_play' column to calculate the weight.

I'm using PHP and Mysql and I'm not sure if I can do the query with just SQL or if I need to get all 10.000 results and then make calculations using PHP.

Could you please help me with the query? Maybe there is a better approach to solve the problem?

The table:

CREATE TABLE `songs` (
    `id` INT(11) NOT NULL AUTO_INCREMENT,
    `name` VARCHAR(50) NULL DEFAULT '0',
    `filename` VARCHAR(150) NULL DEFAULT '0',
    `last_play` TIMESTAMP NULL DEFAULT NULL,
    PRIMARY KEY (`id`)
)
ENGINE=InnoDB
;
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 多址通信方式的抗噪声性能和系统容量对比
    • ¥15 winform的chart曲线生成时有凸起
    • ¥15 msix packaging tool打包问题
    • ¥15 finalshell节点的搭建代码和那个端口代码教程
    • ¥15 Centos / PETSc / PETGEM
    • ¥15 centos7.9 IPv6端口telnet和端口监控问题
    • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
    • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
    • ¥20 海浪数据 南海地区海况数据,波浪数据
    • ¥20 软件测试决策法疑问求解答