Myweblog
Myweblog
2018-04-11 09:50

mysql sql 语句调优 rand()为啥不稳定

10
  • rand()
  • mysql

图片说明

请教一下 第二个sql 为啥 会查出null 数据, 或者出现两条数据 我把sql 贴出来

    SELECT a.id,a.pid 
    FROM `shopinfo` a  
    WHERE a.id=(select id 
                            from ( SELECT id,rand() as random_num 
                                         FROM bookinfo 
                                         where status='1') a 
                            order by a.random_num 
                            limit 1)      




            SELECT a.id,a.pid
            FROM `shopinfo` a  
            WHERE a.id=( SELECT id 
                                    FROM bookinfo 
                                    where status='1'  
                                    order by rand() 
                                    LIMIT 1 )
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

4条回答