22,209
社区成员
发帖
与我相关
我的任务
分享
create procedure my_proc @time1 datetime,@time2 datetime
as
begin
select m.* , (select count(1) from
(
select MatNo , sum(总数) 总数 from
(
select MatNo,sum(InStoTotal)总数
from InSto090210cyr
where datediff(day,InStoDate,@time1)<=0 and datediff (day,InStoDate,@time2)>=0
group by MatNo;
union all
select MatNo,sum(OutStoTotal)总数 from OutSto090210cyr
where datediff(day,OutStoDate,@time1)<=0 and datediff (day,OutStoDate,@time2)>=0
group by MatNo;
) t
group by matno
) n where n.总数 > m.总数) + 1 排名 from
(
select MatNo , sum(总数) 总数 from
(
select MatNo,sum(InStoTotal)总数
from InSto090210cyr
where datediff(day,InStoDate,@time1)<=0 and datediff (day,InStoDate,@time2)>=0
group by MatNo;
union all
select MatNo,sum(OutStoTotal)总数 from OutSto090210cyr
where datediff(day,OutStoDate,@time1)<=0 and datediff (day,OutStoDate,@time2)>=0
group by MatNo;
) t
group by matno
) m
order by 排名
end
create procedure my_proc @time1 datetime,@time2 datetime
as
begin
select MatNo , sum(总数) 总数 , row_number() over(order by sum(总数) desc) 排名 from
(
select MatNo,sum(InStoTotal)总数
from InSto090210cyr
where datediff(day,InStoDate,@time1)<=0 and datediff (day,InStoDate,@time2)>=0
group by MatNo;
union all
select MatNo,sum(OutStoTotal)总数 from OutSto090210cyr
where datediff(day,OutStoDate,@time1)<=0 and datediff (day,OutStoDate,@time2)>=0
group by MatNo;
) t
group by matno
order by 排名
end
create procedure my_proc @time1 datetime,@time2 datetime
as
begin
select MatNo , sum(总数) 总数 from
(
select MatNo,sum(InStoTotal)总数
from InSto090210cyr
where datediff(day,InStoDate,@time1)<=0 and datediff (day,InStoDate,@time2)>=0
group by MatNo;
union all
select MatNo,sum(OutStoTotal)总数 from OutSto090210cyr
where datediff(day,OutStoDate,@time1)<=0 and datediff (day,OutStoDate,@time2)>=0
group by MatNo;
) t
group by matno
end
create PROCEDURE ProStadisToTal090210cyr
(
@time1 datetime,
@time2 datetime
)
as
create table #temple_stadis(MatNo char (6),总数 char(10));
insert into #temple_stadis
select MatNo,sum(InStoTotal)总数
from InSto090210cyr
where datediff(day,InStoDate,@time1)<=0 and datediff (day,InStoDate,@time2)>=0
group by MatNo
union all
select MatNo,sum(OutStoTotal)总数
from OutSto090210cyr
where datediff(day,OutStoDate,@time1)<=0 and datediff (day,OutStoDate,@time2)>=0
group by MatNo;
select MatNo,Sum(总数)总数 from #temple_stadis group by MatNo;