根据计数范围的不同,您可以使用一个查找表,该查找表为每个整数x准确保存x个记录。像这样:
create table counter(num int)insert into counter select 1insert into counter select 2insert into counter select 2insert into counter select 3insert into counter select 3insert into counter select 3insert into counter select 4insert into counter select 4insert into counter select 4insert into counter select 4
然后加入此表:
create table source(age int, gender char(1), num int)insert into source select 40, 'm', 3insert into source select 30, 'f', 2insert into source select 20, 'm', 1--insert into destination(age, gender) select age, gender from source inner join counter on counter.num = source.num
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)