一个很难的sql查询,请高手们帮忙,(200分)

  • 主题发起人 主题发起人 ForeverYoung
  • 开始时间 开始时间
to TYZhang;错了,查询结果好象少了一条记录,厦门有三条记录,变成两条了
你自己在看看
 
嘿嘿,没注意,日期重复不能合并,那么用这个:
select case when 地区 is null then '合计'
when id is null then '小计' else 地区 end 地区,
sum([1号]) [1号],sum([2号]) [2号],sum([3号]) [3号],sum(业绩) 业绩
from (select 地区,newid() id,
case when 日期='2006.01.01' then 收入 else 0 end [1号],
case when 日期='2006.01.02' then 收入 else 0 end [2号],
case when 日期='2006.01.03' then 收入 else 0 end [3号],

收入 [业绩]
from 原始表
)T group by 地区,ID with rollup

带排序的:
select 地区,[1号],[2号],[3号],业绩
from (select case when 地区 is null then 1 else 0 end ord1,
地区 ord2,
case when id is null then 1 else 0 end ord3,
case when 地区 is null then '合计'
when id is null then '小计' else 地区 end 地区,
sum([1号]) [1号],sum([2号]) [2号],sum([3号]) [3号],sum(业绩) 业绩
from (select 地区,newid() id,
case when 日期='2006.01.01' then 收入 else 0 end [1号],
case when 日期='2006.01.02' then 收入 else 0 end [2号],
case when 日期='2006.01.03' then 收入 else 0 end [3号],

收入 [业绩]
from 原始表
)T1 group by 地区,ID with rollup
)T2
order by ord1,ord2,ord3
 
to:TYZhang 还在吗?
 
to TYZhang:你真的很厉害,这次真的可以了,多少分你自己说
 
多人接受答案了。
 
to:TYZhang :嘿嘿,你的qq号码多少,可以透露吗??
 
后退
顶部