当前位置: 代码迷 >> Sql Server >> 一道面试题!该如何解决
  详细解决方案

一道面试题!该如何解决

热度:182   发布时间:2016-04-27 19:24:15.0
一道面试题!
在数据库的商品表中有n (n>1) 条数据,现在我们要随机取一条商品数据,请写出SQL语句(不要采用order by 随机列的方式,请用类分页算法解答)。商品表表名为Product_Table , 取随机数的函数为 Random ( beginNum , endNum ),其中beginNum和endNum为随机数产生的闭合区间的起点值和结束值


------解决方案--------------------
SQL code
--没有random函数--选择n到m条数据1--方法select top  m-n+1 *  from tablea where ID not in (select top n-1 ID from tablea)2--方法select top m-n * from (select top m * from Tablec order by ID asc)a
  相关解决方案