现在有一张表,数据量有十万,有一个字段是空的,现在要按数据量比例给这个字段设置三个不同的值,比如百分之三十的数据设置成1,百分之三十设置成2,剩下的百分之四十设置成3。比例无所谓不固定。
有没有大神教一下啊。。。
--建表
create table t (a number);
--插入两条测试数据
insert into t values(0);
insert into t values(0);
--测试语句
select case
when (select count(1) from t where t.a = 0) =
(select count(1) from t) then
'01'
when (select count(1) from t where t.a = 0) <>
(select count(1) from t) then
'02'
when (select count(1) from t where t.a = 2) <>
(select count(1) from t) then
'03'
when (select count(1) from t where t.a = 2) = 0 then
'04'
else
null
end as b
from dual;
参考:http://bbs.csdn.net/topics/330059135
先将所有的都修改为 3 再将前三分之二的修改为2 再将前三分之一修改为1 ,应该可以实现你要的效果