在SQL Server 2008中分解汇总表

在SQL Server 2008中分解汇总表,第1张

在SQL Server 2008中分解汇总表

根据计数范围的不同,您可以使用一个查找表,该查找表为每个整数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


欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/zaji/5618229.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-15
下一篇 2022-12-15

发表评论

登录后才能评论

评论列表(0条)

保存