六狼论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

新浪微博账号登陆

只需一步,快速开始

搜索
查看: 46|回复: 0

oracle 从每种类型里面抽取随机抽取一个

[复制链接]

升级  71.33%

41

主题

41

主题

41

主题

秀才

Rank: 2

积分
157
 楼主| 发表于 2013-1-26 13:35:52 | 显示全部楼层 |阅读模式
select *
  from (select *
          from tableA
         where type = 'A'
         order by dbms_random.value)
 where rownum = 1
 
union all
select *
  from (select *
          from tableA
         where type = 'B'
         order by dbms_random.value)
 where rownum = 1
union all
select *
  from (select *
          from tableA
         where type = 'C'
         order by dbms_random.value)
 where rownum = 1
 
union all
select *
  from (select *
          from tableA
         where type = 'D'
         order by dbms_random.value)
 where rownum = 1
 
 union all
select *
  from (select *
          from tableA
         where type = 'E'
         order by dbms_random.value)
 where rownum = 1
您需要登录后才可以回帖 登录 | 立即注册 新浪微博账号登陆

本版积分规则

快速回复 返回顶部 返回列表